alert_discord.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 IP",
  45. "value": "\`${alertip}:${port}\`",
  46. "inline": true
  47. },
  48. {
  49. "name": "Server Time",
  50. "value": "$(date)",
  51. "inline": true
  52. }
  53. EOF
  54. )
  55. if [ -n "${alerturl}" ]; then
  56. json+=$(
  57. cat << EOF
  58. ,
  59. {
  60. "name": "More info",
  61. "value": "${alerturl}",
  62. "inline": true
  63. }
  64. EOF
  65. )
  66. fi
  67. if [ -n "${querytype}" ]; then
  68. json+=$(
  69. cat << EOF
  70. ,
  71. {
  72. "name": "Is my Game Server Online?",
  73. "value": "https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}"
  74. }
  75. EOF
  76. )
  77. fi
  78. json+=$(
  79. cat << EOF
  80. ],
  81. "footer": {
  82. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  83. "text": "Sent by LinuxGSM ${version}"
  84. }
  85. }
  86. ]
  87. }
  88. EOF
  89. )
  90. fn_print_dots "Sending Discord alert"
  91. discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  92. if [ -n "${discordsend}" ]; then
  93. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  94. fn_script_log_fail "Sending Discord alert: ${discordsend}"
  95. else
  96. fn_print_ok_nl "Sending Discord alert"
  97. fn_script_log_pass "Sending Discord alert"
  98. fi