summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-05-29 00:38:45 +0200
committerlassulus <lassulus@lassul.us>2022-05-29 01:02:55 +0200
commit4d33f2ebea49e258f833cb6eab0c71485e88397a (patch)
treedafd4bf89873ee61daf66429e471ae7d89bff68a
parent88a61c26119968fee629de120fdffe3e4d6312bd (diff)
l prism.r: add binaergewitter bot
-rw-r--r--lass/1systems/prism/config.nix1
-rw-r--r--lass/2configs/bgt-bot/bgt-check.sh57
-rw-r--r--lass/2configs/bgt-bot/default.nix44
3 files changed, 102 insertions, 0 deletions
diff --git a/lass/1systems/prism/config.nix b/lass/1systems/prism/config.nix
index d174e605..62c6f0b7 100644
--- a/lass/1systems/prism/config.nix
+++ b/lass/1systems/prism/config.nix
@@ -124,6 +124,7 @@ with import <stockholm/lib>;
<stockholm/lass/2configs/container-networking.nix>
<stockholm/lass/2configs/jitsi.nix>
<stockholm/lass/2configs/fysiirc.nix>
+ <stockholm/lass/2configs/bgt-bot>
{
services.tor = {
enable = true;
diff --git a/lass/2configs/bgt-bot/bgt-check.sh b/lass/2configs/bgt-bot/bgt-check.sh
new file mode 100644
index 00000000..30185ba1
--- /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
diff --git a/lass/2configs/bgt-bot/default.nix b/lass/2configs/bgt-bot/default.nix
new file mode 100644
index 00000000..6f9e3370
--- /dev/null
+++ b/lass/2configs/bgt-bot/default.nix
@@ -0,0 +1,44 @@
+{ config, lib, pkgs, ... }:
+let
+
+ bot_port = "7654";
+ irc_channel = "#binaergewitter";
+in
+{
+ krebs.reaktor2.bgt-announce = {
+ hostname = "irc.libera.chat";
+ port = "6697";
+ nick = "bgt-announce";
+ API.listen = "inet://127.0.0.1:${bot_port}";
+ plugins = [
+ {
+ plugin = "register";
+ config = {
+ channels = [
+ irc_channel
+ ];
+ };
+ }
+ ];
+ };
+ systemd.services.check_bgt_show = {
+ startAt = "*:0/5";
+ environment = {
+ IRC_CHANNEL = irc_channel;
+ REAKTOR_PORT = bot_port;
+ };
+ path = with pkgs; [
+ curl
+ gnugrep
+ jq
+ ];
+ script = builtins.readFile ./bgt-check.sh;
+ serviceConfig = {
+ DynamicUser = true;
+ StateDirectory = "bgt-announce";
+ WorkingDirectory = "/var/lib/bgt-announce";
+ PrivateTmp = true;
+ };
+ };
+}
+