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