From b21bdc9e5998a35fac2177963c5d2df7ef34f686 Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Tue, 15 Aug 2023 20:10:59 +0000 Subject: [PATCH] added color support to discord notifications. --- discord.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/discord.sh b/discord.sh index 9a474a5..4f803ff 100755 --- a/discord.sh +++ b/discord.sh @@ -5,7 +5,8 @@ LOCATION=`dirname "$0"` source "${LOCATION}/config.sh" HOOK_ARG="$1" -MESSAGE=`echo "${@:2}" | jq -aRs .` +# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead +MESSAGE=`echo "${@:2}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'` HOOK="general" HOOK_URL=$DISCORD_GENERAL_HOOK @@ -24,5 +25,11 @@ case $HOOK_ARG in ;; esac +# if color detected, update message from "" to "```ansi ```", so it gets displayed correctly +if [[ "$MESSAGE" == *"\\u001b"* ]]; then + MESSAGE="\"\`\`\`ansi\n${MESSAGE:1:-1}\n\`\`\`\"" + # just here to resolve formatting issue in vim "`" +fi + curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id'