alert_discord.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # LinuxGSM alert_discord.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Discord alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  9. cat << EOF
  10. {
  11. "username": "LinuxGSM",
  12. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  13. "file": "content",
  14. "embeds": [
  15. {
  16. "author": {
  17. "name": "LinuxGSM Alert",
  18. "url": "",
  19. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  20. },
  21. "title": "${alerttitle}",
  22. "url": "",
  23. "description": "",
  24. "color": "${alertcolourdec}",
  25. "type": "content",
  26. "thumbnail": {
  27. "url": "${alerticon}"
  28. },
  29. "fields": [
  30. {
  31. "name": "Server Name",
  32. "value": "${servername}"
  33. },
  34. {
  35. "name": "Information",
  36. "value": "${alertmessage}"
  37. },
  38. {
  39. "name": "Game",
  40. "value": "${gamename}",
  41. "inline": true
  42. },
  43. {
  44. "name": "Server Time",
  45. "value": "$(date)",
  46. "inline": true
  47. }
  48. EOF
  49. )
  50. if [ -n "${querytype}" ]; then
  51. json+=$(
  52. cat << EOF
  53. ,
  54. {
  55. "name": "Is my Game Server Online?",
  56. "value": "https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}",
  57. "inline": true
  58. }
  59. EOF
  60. )
  61. fi
  62. json+=$(
  63. cat << EOF
  64. ],
  65. "footer": {
  66. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  67. "text": "Sent by LinuxGSM ${version}"
  68. }
  69. }
  70. ]
  71. }
  72. EOF
  73. )
  74. fn_print_dots "Sending Discord alert"
  75. discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  76. if [ -n "${discordsend}" ]; then
  77. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  78. fn_script_log_fail "Sending Discord alert: ${discordsend}"
  79. else
  80. fn_print_ok_nl "Sending Discord alert"
  81. fn_script_log_pass "Sending Discord alert"
  82. fi