Update stdin2discord.bash
All checks were successful
Push commit / report (push) Successful in 6s

This commit is contained in:
a31 2023-11-18 23:12:18 +03:00
parent 54701da1d9
commit bff7d0ec1e

View File

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