diff options
author | makefu <github@syntax-fehler.de> | 2022-06-07 00:17:23 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2022-06-07 00:17:23 +0200 |
commit | 9c1799914a2e6f2dc736fe2eaad7134602a3d837 (patch) | |
tree | 08347f7f29bc00c3b40be2a49e069268c0163716 /lass/2configs/bgt-bot/bgt-check.sh | |
parent | 1e405be047a79e1abd0c28e52b5009b9675909b8 (diff) | |
parent | bdc80e55411e197f89990e988f8b7e67c084d3d3 (diff) |
Merge remote-tracking branch 'lass/master' into 22.05
Diffstat (limited to 'lass/2configs/bgt-bot/bgt-check.sh')
-rw-r--r-- | lass/2configs/bgt-bot/bgt-check.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lass/2configs/bgt-bot/bgt-check.sh b/lass/2configs/bgt-bot/bgt-check.sh new file mode 100644 index 000000000..30185ba18 --- /dev/null +++ b/lass/2configs/bgt-bot/bgt-check.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# needs in path: +# curl gnugrep jq +# creates and manages $PWD/state +set -xeuf + +send_reaktor(){ + # usage: send_reaktor "text" + echo "send_reaktor: $1" + curl -fsS "http://localhost:$REAKTOR_PORT" \ + -H content-type:application/json \ + -d "$(jq -n \ + --arg text "$1" \ + --arg channel "$IRC_CHANNEL" \ + '{ + command:"PRIVMSG", + params:[$channel,$text] + }' + )" +} + +live=$(shuf -n1 <<EOF +Binärgewitter Liveshow hat begonnen! http://stream.radiotux.de:8000/binaergewitter.mp3 +EOF +) + +offline=$(shuf -n1 <<EOF +Live stream vorbei +EOF +) +error=$(shuf -n1 <<EOF +something went wrong +EOF +) + +if curl -Ss http://stream.radiotux.de:8000 | grep -q 'Mount Point /binaergewitter'; then + state='live' +else + state='offline' +fi +prevstate=$(cat state ||:) + +if test "$state" == "$(cat state)";then + #echo "current and last state is the same ($state), doing nothing" + : +else + echo "API state and last state differ ( '$state' != '$prevstate')" + if test "$state" == 'live';then + send_reaktor "$live" + elif test "$state" == 'offline';then + send_reaktor "$offline" + else + send_reaktor "$error" + fi + echo 'updating state' + printf "%s" "$state" > state +fi |