From 1c03d459ac730d5f71a999bd3dc0451016308ff0 Mon Sep 17 00:00:00 2001 From: Clarth Date: Fri, 15 Mar 2024 14:50:59 -0400 Subject: [PATCH] Add Necesse/chat2discord.sh --- Necesse/chat2discord.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Necesse/chat2discord.sh diff --git a/Necesse/chat2discord.sh b/Necesse/chat2discord.sh new file mode 100644 index 0000000..b426d47 --- /dev/null +++ b/Necesse/chat2discord.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Set your Discord webhook URL +DISCORD_WEBHOOK_URL="XXXXXXXXXXXXX" + +# Set the log file you want to monitor +LOG_FILE="/home/necesse/latest-server-log.txt" + +# Set the string you want to monitor for +MONITOR_STRING="):" +MONITOR_STRING2="(Print)" +MONITOR_STRING3=" connected on slot " + + +# Function to send a message to Discord +send_to_discord() { + local message="$1" + from="Server Chat" + curl -H "Content-Type: application/json" -X POST -d '{"username": "'"$from"'", "content": "'"$message"'", "avatar_url": "https://necessewiki.com/images/7/79/Player_Nav_Icon.png"}' "$DISCORD_WEBHOOK_URL" +} + +# Tail the log file and monitor for the specified string +tail -n 0 -F "$LOG_FILE" | while read line; do + if [[ $line == *"$MONITOR_STRING3"* ]]; then + # When the string is found, send the line to Discord + message=$(echo "$line" | sed -E 's/\[[^]]+\] |"//g') + send_to_discord "$message" + fi + if [[ $line == *"$MONITOR_STRING"* ]] && [[ $line != *"$MONITOR_STRING2"* ]]; then + # Extract the portion of the line after the first '(' character + message="${line#*\(}" + send_to_discord "($message" # Send the modified message to Discord + fi + + + +done