From f4e10ca404b5167482e6702a4f3db3ea9c3e0e1e Mon Sep 17 00:00:00 2001 From: Clarth Date: Tue, 23 Jan 2024 13:40:57 -0500 Subject: [PATCH] Add Minecraft/Modded/Discord.sh --- Minecraft/Modded/Discord.sh | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Minecraft/Modded/Discord.sh diff --git a/Minecraft/Modded/Discord.sh b/Minecraft/Modded/Discord.sh new file mode 100644 index 0000000..8494bea --- /dev/null +++ b/Minecraft/Modded/Discord.sh @@ -0,0 +1,53 @@ +#!/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