Просмотр исходного кода

allow map and player info on alert

Daniel Gibbs 4 лет назад
Родитель
Сommit
92f24b6ab5
3 измененных файлов с 88 добавлено и 44 удалено
  1. 36 2
      lgsm/functions/alert.sh
  2. 51 41
      lgsm/functions/alert_discord.sh
  3. 1 1
      lgsm/functions/info_messages.sh

+ 36 - 2
lgsm/functions/alert.sh

@@ -10,8 +10,6 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 # Generates alert log of the details at the time of the alert.
 # Used with email alerts.
 fn_alert_log(){
-	info_distro.sh
-	info_game.sh
 	info_messages.sh
 	if [ -f "${alertlog}" ]; then
 		rm -f "${alertlog:?}"
@@ -90,6 +88,42 @@ fn_alert_config(){
 	alertbody="${selfname} has received a new _default.cfg. Check file for changes."
 }
 
+info_distro.sh
+info_game.sh
+query_gamedig.sh
+
+# Allow Alert to display gamedig info if available.
+if [ "${querystatus}" != "0" ]; then
+	if [ -n "${maxplayers}" ]; then
+		alertplayerstitle="Maxplayers"
+		alertplayers="-${maxplayers}"
+	fi
+else
+	if [ -n "${gdplayers}" ]&&[ -n "${gdmaxplayers}" ]; then
+		alertplayerstitle="Players"
+		alertplayers="${gdplayers}/${gdmaxplayers}"
+	elif [ -n "${gdplayers}" ]&&[ -n "${maxplayers}" ]; then
+		alertplayerstitle="Players"
+		alertplayers="${gdplayers}/${maxplayers}"
+	elif [ -z "${gdplayers}" ]&&[ -n "${gdmaxplayers}" ]; then
+		alertplayerstitle="Players"
+		alertplayers="-1/${gdmaxplayers}"
+	elif [ -n "${gdplayers}" ]&&[ -z "${gdmaxplayers}" ]; then
+		alertplayerstitle="Players"
+		alertplayers="${gdplayers}/∞"
+	elif [ -z "${gdplayers}" ]&&[ -z "${gdmaxplayers}" ]&&[ -n "${maxplayers}" ]; then
+		alertplayerstitle="Maxplayers"
+		alertplayers="${maxplayers}"
+	fi
+fi
+
+if [ -n "${gdmap}" ]; then
+	alertmap="${gdmap}"
+else
+	alertmap="Unknown"
+fi
+
+
 if [ "${alert}" == "permissions" ]; then
 	fn_alert_permissions
 elif [ "${alert}" == "restart" ]; then

+ 51 - 41
lgsm/functions/alert_discord.sh

@@ -9,53 +9,63 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 json=$(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",
-        "url": "",
-        "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
-      },
-      "title": "${servername}",
-      "url": "",
-      "description": "${alertemoji} ${alertsubject}",
-      "color": 15258703,
-      "fields": [
-        {
-        "name": "Game",
+	"username": "LinuxGSM Alert",
+	"avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
+	"content": "",
+	"embeds": [
+		{
+			"author": {
+				"name": "LinuxGSM",
+				"url": "",
+				"icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
+			},
+			"title": "${servername}",
+			"url": "",
+			"description": "${alertemoji} ${alertsubject}",
+			"color": 15258703,
+			"fields": [
+				{
+				"name": "Game",
 				"value": "${gamename}",
 				"inline": true
-        },
-        {
-        "name": "Server IP",
+				},
+				{
+				"name": "Players",
+				"value": "${alertplayers}",
+				"inline": true
+				},
+				{
+				"name": "Map",
+				"value": "${alertmap}",
+				"inline": true
+				},
+				{
+				"name": "Server IP",
 				"value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
 				"inline": true
-        },
-        {
-        "name": "Hostname",
+				},
+				{
+				"name": "Hostname",
 				"value": "${HOSTNAME}",
 				"inline": true
-        },
-        {
-          "name": "Information",
-          "value": "${alertbody} \n More info: ${alerturl}"
-        }
-      ],
-      "thumbnail": {
-        "url": "https://linuxgsm.com/wp-content/uploads/2020/07/minecraft-bedrock-icon.jpg"
-      },
-      "image": {
-        "url": "https://linuxgsm.com/wp-content/uploads/2021/02/mcbe-header.jpg"
-      },
-      "footer": {
-        "text": "Powered by LinuxGSM",
-        "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
-      }
-    }
-  ]
+				},
+				{
+					"name": "Information",
+					"value": "${alertbody} \n More info: ${alerturl}"
+				}
+			],
+			"thumbnail": {
+				"url": "https://linuxgsm.com/wp-content/uploads/2020/07/minecraft-bedrock-icon.jpg"
+			},
+			"image": {
+				"url": "https://linuxgsm.com/wp-content/uploads/2021/02/mcbe-header.jpg"
+			},
+			"footer": {
+				"text": "Powered by LinuxGSM",
+				"icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
+			}
+		}
+	]
 }
 EOF
 )

+ 1 - 1
lgsm/functions/info_messages.sh

@@ -331,7 +331,7 @@ fn_info_message_gameserver(){
 			elif [ -n "${gdplayers}" ]&&[ -n "${maxplayers}" ]; then
 				echo -e "${lightblue}Players:\t${default}${gdplayers}/${maxplayers}"
 			elif [ -z "${gdplayers}" ]&&[ -n "${gdmaxplayers}" ]; then
-				echo -e "${lightblue}Players:\t${default}0/${gdmaxplayers}"
+				echo -e "${lightblue}Players:\t${default}-1/${gdmaxplayers}"
 			elif [ -n "${gdplayers}" ]&&[ -z "${gdmaxplayers}" ]; then
 				echo -e "${lightblue}Players:\t${default}${gdplayers}/∞"
 			elif [ -z "${gdplayers}" ]&&[ -z "${gdmaxplayers}" ]&&[ -n "${maxplayers}" ]; then