alert_discord.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if [ -n "{alerturl}" ]; then
  63. json+=$(
  64. cat << EOF
  65. ,
  66. {
  67. "name": "More info",
  68. "value": "${alerturl}",
  69. "inline": true
  70. }
  71. EOF
  72. )
  73. fi
  74. json+=$(
  75. cat << EOF
  76. ],
  77. "footer": {
  78. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  79. "text": "Sent by LinuxGSM ${version}"
  80. }
  81. }
  82. ]
  83. }
  84. EOF
  85. )
  86. fn_print_dots "Sending Discord alert"
  87. discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  88. if [ -n "${discordsend}" ]; then
  89. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  90. fn_script_log_fail "Sending Discord alert: ${discordsend}"
  91. else
  92. fn_print_ok_nl "Sending Discord alert"
  93. fn_script_log_pass "Sending Discord alert"
  94. fi