Gamer-Server-Utility-Scripts/Necesse/chat2discord.sh

38 lines
1.1 KiB
Bash
Raw Normal View History

2024-03-15 14:50:59 -04:00
#!/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