CEC-list-monitoring/stdin2discord.bash
norohind 216f7787ea
Some checks failed
Push commit / report (push) Failing after 13s
stdin2discord: add set -x
2023-11-18 23:26:54 +03:00

31 lines
530 B
Bash
Executable File

#!/bin/bash
set -euo pipefail
set -x
send() {
local _msg=$1
if [[ -z $_msg ]]; then
return
fi
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \
"$DISCORD_WEBHOOK"
}
msg=""
while IFS= read -r line; do
line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening
len="$(wc -m <<< "$msg$line")"
if [[ $len -ge 1985 ]]; then
send "$msg"
msg="$line"
else
msg+="$line\\n"
fi
done
send "$msg"