added color support to discord notifications.
This commit is contained in:
+8
-1
@@ -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 "<content>" to "```ansi <content>```", 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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user