Gamer-Server-Utility-Scripts/Minecraft/Modded/Discord.sh

54 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2024-01-23 13:40:57 -05:00
#!/bin/bash
# Custom script for specific use case.
#Probably won't help anyone.
# Set your Discord webhook URL
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/"
# Set the log file you want to monitor
#LOG_FILE="/home/moddedmc/Abe/logs/latest.log"
LOG_FILE="/home/moddedmc/BetterMC/logs/latest.log"
# Set the string you want to monitor for
MONITOR_STRING="joined the game"
MONITOR_STRING2="left the game"
MONITOR_STRING3="Dedicated server took"
# Function to send a message to Discord
send_to_discord() {
local message="$1"
from="Modded_Console"
#curl -X POST -H "Content-Type: application/json" -d "{\"content\":\"$message\"}" "$DISCORD_WEBHOOK_URL"
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/" #Rtabb & Clay
curl -H "Content-Type: application/json" -X POST -d '{"username": "'"$from"'", "content": "'"$message"'", "avatar_url": "https://i.imgur.com/N5YSQsi.png"}' "$DISCORD_WEBHOOK_URL"
}
# Function to send message to discord as ModdedMC instead of Modded_Console
send_to_discord2() {
local message="$1"
from="ModdedMC"
#curl -X POST -H "Content-Type: application/json" -d "{\"content\":\"$message\"}" "$DISCORD_WEBHOOK_URL"
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/" #Rtabb & Clay
curl -H "Content-Type: application/json" -X POST -d '{"username": "'"$from"'", "content": "'"$message"'", "avatar_url": "https://i.imgur.com/oBycxyt.png"}' "$DISCORD_WEBHOOK_URL"
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/" #Claytonia
curl -H "Content-Type: application/json" -X POST -d '{"username": "'"$from"'", "content": "'"$message"'", "avatar_url": "https://i.imgur.com/N5YSQsi.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_STRING"* ]]; then
# When the string is found, send the line to Discord
send_to_discord "$line"
fi
if [[ $line == *"$MONITOR_STRING2"* ]]; then
# When the string is found, send the line to Discord
send_to_discord "$line"
fi
if [[ $line == *"$MONITOR_STRING3"* ]]; then
# When the string is found, send the line to Discord
send_to_discord2 "Server is online. You can connect now!"
fi
done