From 45c220a471c2a3a9b35387609b712d233a8583aa Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 18 Aug 2024 20:47:11 +0100 Subject: [PATCH] add ismygameserveronline --- lgsm/modules/alert_discord.sh | 102 +++++++--------------------------- 1 file changed, 21 insertions(+), 81 deletions(-) diff --git a/lgsm/modules/alert_discord.sh b/lgsm/modules/alert_discord.sh index c98bef765..d5b1c464e 100644 --- a/lgsm/modules/alert_discord.sh +++ b/lgsm/modules/alert_discord.sh @@ -7,7 +7,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "username": "LinuxGSM", @@ -29,14 +29,14 @@ jsoninfo=$( "url": "${alerticon}" }, "fields": [ - { - "name": "Server Name", - "value": "${servername}" - }, - { - "name": "Information", - "value": "${alertmessage}" - }, + { + "name": "Server Name", + "value": "${servername}" + }, + { + "name": "Information", + "value": "${alertmessage}" + }, { "name": "Game", "value": "${gamename}", @@ -52,80 +52,26 @@ jsoninfo=$( "value": "${HOSTNAME}", "inline": true }, +EOF +) + +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF { "name": "Is my Game Server Online?", "value": "https://ismygameserver.online/${querytype}/${alertip}:${queryport}", "inline": true }, - { - "name": "More info", - "value": "${alerturl}", - "inline": true - }, - { - "name": "Server Time", - "value": "$(date)", - "inline": true - } - ], - "footer": { - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "text": "Sent by LinuxGSM ${version}" - } - } - ] -} EOF -) + ) +fi -jsonnoinfo=$( +json+=$( cat << EOF -{ - "username": "LinuxGSM", - "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "file": "content", - "embeds": [ - { - "author": { - "name": "LinuxGSM Alert", - "url": "", - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg" - }, - "title": "${alerttitle}", - "url": "", - "description": "", - "color": "${alertcolourdec}", - "type": "content", - "thumbnail": { - "url": "${alerticon}" - }, - "fields": [ - { - "name": "Server Name", - "value": "${servername}" - }, - { - "name": "Information", - "value": "${alertmessage}" - }, - { - "name": "Game", - "value": "${gamename}", - "inline": true - }, { - "name": "Server IP", - "value": "\`${alertip}:${port}\`", - "inline": true - }, - { - "name": "Hostname", - "value": "${HOSTNAME}", - "inline": true - }, - { - "name": "Is my Game Server Online?", - "value": "https://ismygameserver.online/${querytype}/${alertip}:${queryport}", + "name": "More info", + "value": "${alerturl}", "inline": true }, { @@ -135,7 +81,7 @@ jsonnoinfo=$( } ], "footer": { - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", + "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", "text": "Sent by LinuxGSM ${version}" } } @@ -146,12 +92,6 @@ EOF fn_print_dots "Sending Discord alert" -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}") if [ -n "${discordsend}" ]; then