From 7264fce03cf2785b78c3f00bd18a34f9cf4871b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 23 Aug 2022 14:47:24 +0200 Subject: [PATCH] feat(telegram-bots): add smyth --- configs/telegram-bots/default.nix | 1 + configs/telegram-bots/smyth.nix | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 configs/telegram-bots/smyth.nix diff --git a/configs/telegram-bots/default.nix b/configs/telegram-bots/default.nix index fabc741..42e307f 100644 --- a/configs/telegram-bots/default.nix +++ b/configs/telegram-bots/default.nix @@ -19,6 +19,7 @@ in { ./astrology.nix ./autorenkalender.nix ./hesychius.nix + ./smyth.nix ./nachtischsatan.nix ./tlg-wotd.nix diff --git a/configs/telegram-bots/smyth.nix b/configs/telegram-bots/smyth.nix new file mode 100644 index 0000000..f67fdf0 --- /dev/null +++ b/configs/telegram-bots/smyth.nix @@ -0,0 +1,35 @@ +{ + pkgs, + lib, + ... +}: { + niveum.telegramBots.smyth = { + enable = true; + time = "08/6:00"; + token = lib.strings.fileContents ; + chatIds = ["@HerbertWeirSmyth"]; + command = toString (pkgs.writers.writeDash "random-smyth" '' + set -efu + + RANDOM_SECTION=$( + ${pkgs.curl}/bin/curl -sSL http://www.perseus.tufts.edu/hopper/xmltoc?doc=Perseus%3Atext%3A1999.04.0007%3Asmythp%3D1 \ + | ${pkgs.gnugrep}/bin/grep -o 'ref="[^"]*"' \ + | ${pkgs.coreutils}/bin/shuf -n1 \ + | ${pkgs.gnused}/bin/sed 's/^ref="//;s/"$//' + ) + + ${pkgs.curl}/bin/curl -sSL http://www.perseus.tufts.edu/hopper/text?doc=$RANDOM_SECTION\ + | ${pkgs.htmlq}/bin/htmlq '#text_main' \ + | ${pkgs.gnused}/bin/sed 's/<\/\?hr>//g' \ + | ${pkgs.pandoc}/bin/pandoc -f html -t plain --wrap=none + ''); + }; + + niveum.passport.services = [ + { + title = "Herbert Weir Smyth Bot"; + description = "sends a random section from Smyth's Ancient Greek grammar to Telegram."; + link = "https://t.me/HerbertWeirSmyth"; + } + ]; +}