dynv6 now defaults to config, discord displays error message on error.

This commit is contained in:
2023-09-27 09:54:21 -04:00
parent 80f28a0af8
commit 6e337e3911
4 changed files with 35 additions and 18 deletions
+6 -4
View File
@@ -1,4 +1,4 @@
# internal function to transmit a discord chunk
# internal function to transmit a chunk of text to Discord
function SendDiscordMessage
{
param (
@@ -17,19 +17,21 @@ function SendDiscordMessage
$botName = ConvertTo-Json -InputObject $botName
# rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead
# windows is fine with the missing zero, but discord needs it
# windows is fine with the missing zero, but Discord needs it
$message = $message -Replace "\\u001b\[m", "\u001b[0m"
# remove wrapping quotes around json string, replace with color-enabled block quotes
$message = '"```ansi\n' + $message.SubString(1, $message.length - 2) + '\n```"'
# {"username": "$botName", "content": "$message"}
# build post data: {"username": "$botName", "content": "$message"}
$content = "{";
if ($botName) {
$content += '"username": ' + $botName + ', ';
}
$content += '"content": ' + $message + '}';
echo "$content" | curl.exe -s -H "$header" -X "POST" -d "@-" "$webhook" | ConvertFrom-Json | Select-Object -Property id | Out-Host
# post data is complex, so we have to pipe it into curl
# display the resulting id/message returned from Discord
echo "$content" | curl.exe -s -H "$header" -X "POST" -d "@-" "$webhook" | ConvertFrom-Json | Select-Object -Property id, message
}