Spielername in Meldungen in Anführungszeichen gesetzt; Sanitizing beibehalten
This commit is contained in:
parent
9c297ab7b1
commit
3d9f700d42
@ -4,9 +4,9 @@
|
|||||||
# Autor: Patrick Asmus
|
# Autor: Patrick Asmus
|
||||||
# Web: https://www.cleveradmin.de
|
# Web: https://www.cleveradmin.de
|
||||||
# Repository: https://git.techniverse.net/scriptos/minecraft-ntfy-notify
|
# Repository: https://git.techniverse.net/scriptos/minecraft-ntfy-notify
|
||||||
# Version: 1.1
|
# Version: 1.2
|
||||||
# Datum: 18.09.2025
|
# Datum: 18.09.2025
|
||||||
# Modifikation: ANSI/MC-Farbcodes strippen, robustes Schreiben der Playerliste
|
# Modifikation: Spielername in Meldungen in Anführungszeichen gesetzt; Sanitizing beibehalten
|
||||||
#####################################################
|
#####################################################
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@ -69,7 +69,6 @@ ensure_state() {
|
|||||||
|
|
||||||
# Strippt ANSI-Escape-Sequenzen, MC-Farbcodes (§x), CR und Steuerzeichen
|
# Strippt ANSI-Escape-Sequenzen, MC-Farbcodes (§x), CR und Steuerzeichen
|
||||||
sanitize() {
|
sanitize() {
|
||||||
# stdin -> stdout
|
|
||||||
sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g' \
|
sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g' \
|
||||||
| sed -E 's/§[0-9A-FK-ORa-fk-or]//g' \
|
| sed -E 's/§[0-9A-FK-ORa-fk-or]//g' \
|
||||||
| tr -d '\r' \
|
| tr -d '\r' \
|
||||||
@ -83,14 +82,11 @@ get_players() {
|
|||||||
fi
|
fi
|
||||||
dbg "RAW: $out"
|
dbg "RAW: $out"
|
||||||
|
|
||||||
# Normalisieren & Farbcodes raus
|
|
||||||
out="$(printf '%s' "$out" | sanitize)"
|
out="$(printf '%s' "$out" | sanitize)"
|
||||||
|
|
||||||
# Erwartete Muster:
|
|
||||||
# "There are 0 of a max of 20 players online"
|
# "There are 0 of a max of 20 players online"
|
||||||
# "There are 2 of a max of 20 players online: Alice, Bob"
|
# "There are 2 of a max of 20 players online: Alice, Bob"
|
||||||
if ! grep -q "players online:" <<<"$out"; then
|
if ! grep -q "players online:" <<<"$out"; then
|
||||||
# Kein Spieler gelistet, aber kein Fehler
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -100,7 +96,6 @@ get_players() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Namen splitten, trimmen, doppelte raus, sortiert liefern
|
|
||||||
printf '%s\n' "$names" \
|
printf '%s\n' "$names" \
|
||||||
| tr ',' '\n' \
|
| tr ',' '\n' \
|
||||||
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
|
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
|
||||||
@ -150,7 +145,7 @@ while :; do
|
|||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
[[ -z "$name" ]] && continue
|
[[ -z "$name" ]] && continue
|
||||||
ntfy_notify "${NTFY_TITLE_PREFIX}: Join" \
|
ntfy_notify "${NTFY_TITLE_PREFIX}: Join" \
|
||||||
"Player ${name} ist beigetreten." \
|
"Player \"${name}\" ist beigetreten." \
|
||||||
"${NTFY_TAGS_BASE},join" "$NTFY_PRIORITY_JOIN" || true
|
"${NTFY_TAGS_BASE},join" "$NTFY_PRIORITY_JOIN" || true
|
||||||
done <<<"$joined"
|
done <<<"$joined"
|
||||||
fi
|
fi
|
||||||
@ -158,7 +153,7 @@ while :; do
|
|||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
[[ -z "$name" ]] && continue
|
[[ -z "$name" ]] && continue
|
||||||
ntfy_notify "${NTFY_TITLE_PREFIX}: Leave" \
|
ntfy_notify "${NTFY_TITLE_PREFIX}: Leave" \
|
||||||
"Player ${name} hat den Server verlassen." \
|
"Player \"${name}\" hat den Server verlassen." \
|
||||||
"${NTFY_TAGS_BASE},leave" "$NTFY_PRIORITY_LEAVE" || true
|
"${NTFY_TAGS_BASE},leave" "$NTFY_PRIORITY_LEAVE" || true
|
||||||
done <<<"$left"
|
done <<<"$left"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user