ddns and discord on windows now support being quieter with -quiet switch.

This commit is contained in:
2023-11-15 08:28:43 -05:00
parent 44f2ca09ad
commit 161ca4c691
2 changed files with 18 additions and 8 deletions
+6 -2
View File
@@ -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,8 +95,11 @@ end {
if (($oldMessage -join "`n") -ne ($message -join "`n")) {
# finally send each chunk of the message
foreach ($chunk in $chunks) {
# 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
if ($distinct) {
+9 -3
View File
@@ -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) {
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) {
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")
}