From f735d660dca8f2077d5fdcef7dad53cd201a0019 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Fri, 20 Oct 2023 20:17:32 +0300 Subject: [PATCH] fix stdin2discord.bash screening problems, msg len measurement --- stdin2discord.bash | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdin2discord.bash b/stdin2discord.bash index 3c04fb1..1a7b5ca 100644 --- a/stdin2discord.bash +++ b/stdin2discord.bash @@ -9,18 +9,20 @@ send() { curl -X POST \ -H "Content-Type: application/json" \ - -d "{\"content\":\"$_msg\"}" \ + -d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \ "$DISCORD_WEBHOOK" } msg="" while IFS= read -r line; do - if [[ ${#msg}${#line} -ge 2000 ]]; then + line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening + len="$(wc -m <<< "$msg$line")" + if [[ $len -ge 1985 ]]; then send "$msg" - msg="" + msg="$line" else - msg+="$line" + msg+="$line\\n" fi done