Browse Source
refactor: simplify Discord and Pushbullet alert message handling
The code changes in this commit refactor the way Discord and Pushbullet alert messages are handled. The previous implementation used separate variables for short information and no information scenarios, but now it uses a single variable for both cases. Additionally, the code now checks if the "alerturl" is empty instead of comparing it to a specific value.
These changes improve code readability and maintainability by reducing redundancy and simplifying conditional logic.
pull/4345/head
Daniel Gibbs
2 years ago
No known key found for this signature in database
GPG Key ID: 2076B128385E8C55
2 changed files with
24 additions and
7 deletions
lgsm/modules/alert_discord.sh
lgsm/modules/alert_pushbullet.sh
@ -7,7 +7,7 @@
moduleselfname = " $( basename " $( readlink -f " ${ BASH_SOURCE [0] } " ) " ) "
jsonshort info = $(
jsoninfo = $(
cat << EOF
{
"username" : "LinuxGSM" ,
@ -63,7 +63,7 @@ jsonshortinfo=$(
EOF
)
jsonshort noinfo = $(
jsonnoinfo = $(
cat << EOF
{
"username" : "LinuxGSM" ,
@ -117,10 +117,10 @@ EOF
fn_print_dots "Sending Discord alert"
if [ " ${ alerturl } " = = "not enabled " ] ; then
json = " ${ jsonshort noinfo } "
if [ -z " ${ alerturl } " ] ; then
json = " ${ jsonnoinfo } "
else
json = " ${ jsonshort info } "
json = " ${ jsoninfo } "
fi
discordsend = $( curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d " $( echo -n " ${ json } " | jq -c .) " " ${ discordwebhook } " )
@ -7,17 +7,34 @@
moduleselfname = " $( basename " $( readlink -f " ${ BASH_SOURCE [0] } " ) " ) "
json = $(
jsoninfo = $(
cat << EOF
{
"channel_tag" : " ${ channeltag } " ,
"type" : "note" ,
"title" : " ${ alertemoji } ${ alerttitle } ${ alertemoji } " ,
"body" : " Server name\n ${ servername } \n\nMessage \n ${ alertmessage } \n\nGame\n ${ gamename } \n\nServer IP\n ${ alertip } : ${ port } \n\nHostname\n ${ HOSTNAME } \n\nMore info\n ${ alerturl } "
"body" : " Server name\n ${ servername } \n\nInformation \n ${ alertmessage } \n\nGame\n ${ gamename } \n\nServer IP\n ${ alertip } : ${ port } \n\nHostname\n ${ HOSTNAME } \n\nMore info\n ${ alerturl } "
}
EOF
)
jsonnoinfo = $(
cat << EOF
{
"channel_tag" : " ${ channeltag } " ,
"type" : "note" ,
"title" : " ${ alertemoji } ${ alerttitle } ${ alertemoji } " ,
"body" : " Server name\n ${ servername } \n\nInformation\n ${ alertmessage } \n\nGame\n ${ gamename } \n\nServer IP\n ${ alertip } : ${ port } \n\nHostname\n ${ HOSTNAME } "
}
EOF
)
if [ -z " ${ alerturl } " ] ; then
json = " ${ jsonnoinfo } "
else
json = " ${ jsoninfo } "
fi
fn_print_dots "Sending Pushbullet alert"
pushbulletsend = $( curl --connect-timeout 10 -sSL -H " Access-Token: ${ pushbullettoken } " -H "Content-Type: application/json" -X POST -d " $( echo -n " ${ json } " | jq -c .) " "https://api.pushbullet.com/v2/pushes" | grep "error_code" )