init
This commit is contained in:
30
AdminPi/listener.sh
Normal file
30
AdminPi/listener.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user