discord to auto-split large messages.

This commit is contained in:
2023-08-15 21:21:08 +00:00
parent b21bdc9e59
commit bd1df30840
+15 -1
View File
@@ -5,8 +5,18 @@ LOCATION=`dirname "$0"`
source "${LOCATION}/config.sh"
HOOK_ARG="$1"
MESSAGE=`echo "${@:2}"`
# if message is too long, split it, and after curl, recursively call with remainder
# 2k max, but we must account for escaping text in json, so limit to 90% capacity
EXTRA="${MESSAGE:1800}"
if [ -n "${EXTRA}" ]; then
MESSAGE="${MESSAGE:0:1800}"
fi
# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead
MESSAGE=`echo "${@:2}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'`
MESSAGE=`echo "${MESSAGE}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'`
HOOK="general"
HOOK_URL=$DISCORD_GENERAL_HOOK
@@ -33,3 +43,7 @@ fi
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id'
if [ -n "${EXTRA}" ]; then
"${LOCATION}/discord.sh" "${HOOK}" "${EXTRA}"
fi