Browse Source

Design tweaks and JSON-safe escaping string

pull/2045/head
diamondburned 7 years ago
committed by GitHub
parent
commit
450e0fc423
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 92
      lgsm/functions/alert_discord.sh

92
lgsm/functions/alert_discord.sh

@ -5,60 +5,62 @@
# Website: https://linuxgsm.com # Website: https://linuxgsm.com
# Description: Sends Discord alert. # Description: Sends Discord alert.
if ! command -v jq > /dev/null; then
fn_print_fail_nl "Sending Discord alert: jq is missing."
fn_script_log_fatal "Sending Discord alert: jq is missing."
fi
EscapedServername="$(echo -n "${servername}" | jq -sRr "@json")"
EscapedAlertBody="$(echo -n "${alertbody}" | jq -sRr "@json")"
echo "$servername" > /tmp/servername
json=$(cat <<EOF json=$(cat <<EOF
{ {
"username":"LinuxGSM", "username":"LinuxGSM",
"avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/data/alert_discord_logo.png", "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/data/alert_discord_logo.png",
"file":"content", "file":"content",
"embeds": [{ "embeds": [{
"color": "2067276", "color": "2067276",
"author": {"name": "${alertemoji} ${alertsubject} ${alertemoji}", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"}, "author": {"name": "${alertemoji} ${alertsubject}", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"},
"title": "", "title": "",
"description": "", "description": ${EscapedAlertBody},
"url": "", "url": "",
"type": "content", "type": "content",
"thumbnail": {"url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"}, "thumbnail": {},
"footer": {"text": "LinuxGSM", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"}, "footer": {"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}", "icon_url": ""},
"fields": [ "fields": [
{ {
"name": "Alert Message", "name": "Game",
"value": "${alertbody}" "value": "${gamename}",
}, "inline": true
{ },
"name": "Game", {
"value": "${gamename}" "name": "Server IP",
}, "value": "[${extip:-$ip}:${port}](https://www.gametracker.com/server_info/${extip:-$ip}:${port})",
{ "inline": true
"name": "Server name", },
"value": "${servername}" {
}, "name": "Server name",
{ "value": ${EscapedServername},
"name": "Hostname", "inline": true
"value": "${HOSTNAME}" }
}, ]
{ }]
"name": "Server IP",
"value": "[${extip:-$ip}:${port}](https://www.gametracker.com/server_info/${extip:-$ip}:${port})"
},
{
"name": "More info",
"value": "${alerturl}"
}
]
}]
} }
EOF EOF
) )
fn_print_dots "Sending Discord alert" fn_print_dots "Sending Discord alert"
sleep 0.5
discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "${discordwebhook}") minified="$(echo -n "$json" | jq -c -M "@json")"
discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d "${json}" "${discordwebhook}")
if [ -n "${discordsend}" ]; then if [ -n "${discordsend}" ]; then
fn_print_fail_nl "Sending Discord alert: ${discordsend}" fn_print_fail_nl "Sending Discord alert: ${discordsend}"
fn_script_log_fatal "Sending Discord alert: ${discordsend}" fn_script_log_fatal "Sending Discord alert: ${discordsend}"
else else
fn_print_ok_nl "Sending Discord alert" fn_print_ok_nl "Sending Discord alert"
fn_script_log_pass "Sending Discord alert" fn_script_log_pass "Sending Discord alert"
fi fi

Loading…
Cancel
Save