30 lines
763 B
Bash
30 lines
763 B
Bash
#!/bin/bash
|
|
|
|
# Your command to run on "/start"
|
|
execute_command() {
|
|
echo "Received /start command! Executing..."
|
|
# Replace this line with your actual command
|
|
your_command_here
|
|
}
|
|
|
|
while true; do
|
|
now=$(date +%s)
|
|
cutoff=$((now - 8))
|
|
|
|
# Get all messages from the server
|
|
response=$(curl -s "https://ntfy.spaeth-bayern.de/MC/json?poll=1")
|
|
|
|
# Get the last (most recent) message line
|
|
last_line=$(echo "$response" | tail -n 1)
|
|
|
|
# Extract timestamp and message
|
|
msg_time=$(echo "$last_line" | jq -r '.time')
|
|
msg_text=$(echo "$last_line" | jq -r '.message')
|
|
|
|
# Check if message is recent and is "/start"
|
|
if [[ "$msg_time" -ge "$cutoff" && "$msg_text" == "/start" ]]; then
|
|
execute_command
|
|
fi
|
|
|
|
sleep 5
|
|
done |