ソースを参照

testing alert short

Daniel Gibbs 4 年 前
コミット
6345cc499e
2 ファイル変更35 行追加0 行削除
  1. 2 0
      lgsm/functions/alert.sh
  2. 33 0
      lgsm/functions/alert_discord.sh

+ 2 - 0
lgsm/functions/alert.sh

@@ -43,6 +43,7 @@ fn_alert_test(){
 
 fn_alert_stopping(){
 	fn_script_log_info "Sending alert: Stopping"
+	alerttype="short"
 	alerttitle="Alert - ${selfname} - Stopping"
 	alertemoji="🟡"
 	alertsound="1"
@@ -54,6 +55,7 @@ fn_alert_stopping(){
 
 fn_alert_stopped(){
 	fn_script_log_info "Sending alert: Stopped"
+	alerttype="short"
 	alerttitle="Alert - ${selfname} - Stopped"
 	alertemoji="🔴"
 	alertsound="1"

+ 33 - 0
lgsm/functions/alert_discord.sh

@@ -7,6 +7,35 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
+jsonshort=$(cat <<EOF
+{
+	"username": "LinuxGSM Alert",
+	"avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
+	"content": "",
+	"embeds": [
+		{
+			"author": {
+				"name": "LinuxGSM Alert",
+				"url": "",
+				"icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
+			},
+			"title": "${servername}",
+			"url": "",
+			"description": "${alertemoji} ${alerttitle} ${alertemoji}",
+			"color": "${alertcolourdec}",
+			"thumbnail": {
+				"url": "${alerticon}"
+			},
+			"footer": {
+				"text": "Powered by LinuxGSM ${version}",
+				"icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
+			}
+		}
+	]
+}
+EOF
+)
+
 json=$(cat <<EOF
 {
 	"username": "LinuxGSM Alert",
@@ -83,6 +112,10 @@ json=$(cat <<EOF
 EOF
 )
 
+if [ "${alerttype}" == "${short}" ]; then
+	json="${jsonshort}"
+fi
+
 fn_print_dots "Sending Discord alert"
 
 discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")