From 161ca4c69108bee451df2aeda55740a3cbddff95 Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Wed, 15 Nov 2023 08:28:43 -0500 Subject: [PATCH] ddns and discord on windows now support being quieter with -quiet switch. --- Discord.ps1 | 10 +++++++--- Dynv6.ps1 | 16 +++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Discord.ps1 b/Discord.ps1 index 9286505..9894863 100644 --- a/Discord.ps1 +++ b/Discord.ps1 @@ -31,7 +31,8 @@ param ( [string] $webhook = "", [string] $botName = "", [string] $color = "", - [string] $title = "" + [string] $title = "", + [switch] $quiet ) begin { $chunk = "" @@ -56,7 +57,7 @@ begin { process { # build up the full message foreach ($line in $message) { - if ($chunk.length + $line.length -gt 1800) { + if ($chunk.length + $line.length -gt 3600) { # if adding the line will make it too long, queue existing chunk and reset $chunks += $chunk $chunk = "" @@ -94,7 +95,10 @@ end { if (($oldMessage -join "`n") -ne ($message -join "`n")) { # finally send each chunk of the message foreach ($chunk in $chunks) { - SendDiscordMessage -message $chunk -webhook $webhook -botName $botName -title $title -color $colorNumber + # if quiet flag given, and trimmed content is empty then skip, (normally) otherwise send message + if ($chunk.trim() || ! $quiet) { + SendDiscordMessage -message $chunk -webhook $webhook -botName $botName -title $title -color $colorNumber + } } # if distinct, store the updated message for future checking diff --git a/Dynv6.ps1 b/Dynv6.ps1 index 77971d2..c9bbd3f 100644 --- a/Dynv6.ps1 +++ b/Dynv6.ps1 @@ -47,7 +47,8 @@ param( [string] $netmask = "128", [object] $logFile = "$env:USERPROFILE\\.dynv6.log", [string] $ipv4 = "", - [string] $ipv6 = "" + [string] $ipv6 = "", + [switch] $quiet ) # load in defaults from config @@ -100,7 +101,9 @@ $ipv6 = "$ipv6/$netmask" # update IPv4, if changed if ($old4 -eq $ipv4) { - $events += "IPv4 address unchanged" + if ( ! $quiet) { + $events += "IPv4 address unchanged" + } } else { # send IPv4 address to dynv6 $body = @{ @@ -117,7 +120,9 @@ if ($old4 -eq $ipv4) { # update IPv6, if changed if ($old6 -eq $ipv6) { - $events += "IPv6 address unchanged" + if ( ! $quiet) { + $events += "IPv6 address unchanged" + } } else { # send IPv6 address to dynv6 $body = @{ @@ -135,5 +140,6 @@ if ($old6 -eq $ipv6) { if ($logFile) { Out-File -FilePath $logFile -Append -InputObject ($events -join "`n") } -echo ($events -join "`n") - +if ($events.count -gt 0) { + echo ($events -join "`n") +}