From 12b0443bebc03cac30e496a87dc6fc8c11fd9102 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Thu, 17 Sep 2020 14:01:14 +0100 Subject: [PATCH] escaped_servername is now standard --- lgsm/functions/alert.sh | 11 +++- lgsm/functions/alert_discord.sh | 3 - lgsm/functions/alert_ifttt.sh | 2 +- lgsm/functions/alert_pushbullet.sh | 2 +- lgsm/functions/alert_pushover.sh | 2 +- lgsm/functions/alert_rocketchat.sh | 4 +- lgsm/functions/alert_slack.sh | 98 +++++++++++++++--------------- lgsm/functions/alert_telegram.sh | 5 +- 8 files changed, 66 insertions(+), 61 deletions(-) diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index 162b296eb..364d76f10 100755 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -7,9 +7,6 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_alert_log(){ - info_distro.sh - info_config.sh - info_messages.sh if [ -f "${alertlog}" ]; then rm -f "${alertlog:?}" fi @@ -78,6 +75,14 @@ fn_alert_config(){ alertbody="${selfname} has received a new _default.cfg. Check file for changes." } +info_distro.sh +info_config.sh +info_messages.sh + +# JSON-safe escaping string. - use this is json based alerts +escaped_servername=$(echo -n "${servername}" | jq -sRr "@json") +escaped_alertbody=$(echo -n "${alertbody}" | jq -sRr "@json") + if [ "${alert}" == "permissions" ]; then fn_alert_permissions elif [ "${alert}" == "restart" ]; then diff --git a/lgsm/functions/alert_discord.sh b/lgsm/functions/alert_discord.sh index ac9923d09..8c126c384 100755 --- a/lgsm/functions/alert_discord.sh +++ b/lgsm/functions/alert_discord.sh @@ -12,9 +12,6 @@ if ! command -v jq > /dev/null; then fn_script_log_fatal "Sending Discord alert: jq is missing." fi -escaped_servername=$(echo -n "${servername}" | jq -sRr "@json") -escaped_alertbody=$(echo -n "${alertbody}" | jq -sRr "@json") - json=$(cat <${alertemoji} ${alertsubject} ${alertemoji}\n\nMessage\n${alertbody}\n\nGame\n${gamename}\n\nServer name\n${servername}\n\nHostname\n${HOSTNAME}\n\nServer IP\n${alertip}:${port}\n\nMore info\n${alerturl}", + "text": "${alertemoji} ${alertsubject} ${alertemoji}\n\nMessage\n${escaped_alertbody}\n\nGame\n${gamename}\n\nServer name\n${escaped_servername}\n\nHostname\n${HOSTNAME}\n\nServer IP\n${alertip}:${port}\n\nMore info\n${alerturl}", "disable_web_page_preview": "yes", EOF )