Add Necesse/player-count2discord.sh
This commit is contained in:
parent
d7416f87d3
commit
d2892e2471
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /home/necesse/logs/
|
||||||
|
#finds latest file in a dir
|
||||||
|
file="$(ls -1rt /home/necesse/logs | tail -n1)"
|
||||||
|
#finds the line and cuts out the date
|
||||||
|
players=$(grep 'Found' "$file" | cut -c23-)
|
||||||
|
#sends to claytonia #necesse channel
|
||||||
|
DISCORD_WEBHOOK_URL="XXXXXXXXXXX"
|
||||||
|
|
||||||
|
send_to_discord() {
|
||||||
|
from="NecesseBot"
|
||||||
|
curl -H "Content-Type: application/json" -X POST -d '{"username": "'"$from"'", "content": "'"$players"'", "avatar_url": "https://necessewiki.com/images/7/79/Player_Nav_Icon.png"}' "$DISCORD_WEBHOOK_URL"
|
||||||
|
}
|
||||||
|
send_to_discord
|
||||||
|
|
||||||
|
cd /home/necesse/
|
||||||
|
lastmonth=$(cat /home/necesse/player_count.log)
|
||||||
|
echo $lastmonth
|
||||||
|
|
||||||
|
grep -E "\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\] Found [0-9]+ saved players\." latest-server-log.txt | awk '{ match($0, /Found ([0-9]+) saved players\./, arr); print arr[1]; }' > /home/necesse/player_count.log
|
||||||
|
thismonth=$(cat /home/necesse/player_count.log)
|
||||||
|
echo $thismonth
|
||||||
|
|
||||||
|
|
||||||
|
# Calculate the difference and store it in a variable named "difference"
|
||||||
|
difference=$((thismonth - lastmonth))
|
||||||
|
|
||||||
|
# Print the result to verify
|
||||||
|
players=$(echo "$difference New players have joined the server in the last 15 days!")
|
||||||
|
echo $players
|
||||||
|
send_to_discord
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exit
|
Loading…
Reference in New Issue