alert_discord.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # LinuxGSM alert_discord.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Discord alert.
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. jsonshort=$(cat <<EOF
  9. {
  10. "username": "LinuxGSM Alert",
  11. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  12. "content": "",
  13. "embeds": [
  14. {
  15. "author": {
  16. "name": "${servername}",
  17. "url": "",
  18. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  19. },
  20. "title": "${alertemoji} ${alerttriggermessage}",
  21. "url": "",
  22. "description": "",
  23. "color": "${alertcolourdec}",
  24. "thumbnail": {
  25. "url": "${alerticon}"
  26. }
  27. }
  28. ]
  29. }
  30. EOF
  31. )
  32. json=$(cat <<EOF
  33. {
  34. "username": "LinuxGSM Alert",
  35. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  36. "content": "",
  37. "embeds": [
  38. {
  39. "author": {
  40. "name": "LinuxGSM Alert",
  41. "url": "",
  42. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  43. },
  44. "title": "${servername}",
  45. "url": "",
  46. "description": "${alertemoji} ${alerttitle}",
  47. "color": "${alertcolourdec}",
  48. "fields": [
  49. {
  50. "name": "Game",
  51. "value": "${gamename}"
  52. },
  53. {
  54. "name": "${alertplayerstitle}",
  55. "value": "${alertplayers}",
  56. "inline": true
  57. },
  58. {
  59. "name": "Map",
  60. "value": "${alertmap}",
  61. "inline": true
  62. },
  63. {
  64. "name": "Version",
  65. "value": "${alertversion}",
  66. "inline": true
  67. },
  68. {
  69. "name": "Country",
  70. "value": "${countryflag} ${country}",
  71. "inline": true
  72. },
  73. {
  74. "name": "Server IP",
  75. "value": "${alertip}:${port}",
  76. "inline": true
  77. },
  78. {
  79. "name": "Hostname",
  80. "value": "${HOSTNAME}",
  81. "inline": true
  82. },
  83. {
  84. "name": "Trigger Message",
  85. "value": "${alerttriggermessage}"
  86. },
  87. {
  88. "name": "More Info",
  89. "value": "${alertmoreinfourl}"
  90. }
  91. ],
  92. "thumbnail": {
  93. "url": "${alerticon}"
  94. },
  95. "image": {
  96. "url": "${alertimage}"
  97. },
  98. "footer": {
  99. "text": "Powered by LinuxGSM ${version}",
  100. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  101. }
  102. }
  103. ]
  104. }
  105. EOF
  106. )
  107. if [ "${alerttype}" == "short" ]; then
  108. json="${jsonshort}"
  109. fi
  110. fn_print_dots "Sending Discord alert"
  111. discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  112. if [ -n "${discordsend}" ]; then
  113. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  114. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  115. else
  116. fn_print_ok_nl "Sending Discord alert"
  117. fn_script_log_pass "Sending Discord alert"
  118. fi