1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/configs/bots/smyth.nix

73 lines
2.1 KiB
Nix
Raw Normal View History

2022-08-23 14:47:24 +02:00
{
config,
2022-08-23 14:47:24 +02:00
pkgs,
lib,
...
2025-12-27 22:22:54 +01:00
}:
{
2024-10-05 14:42:44 +02:00
niveum.bots.smyth = {
2022-08-23 14:47:24 +02:00
enable = true;
2022-10-14 15:20:19 +02:00
time = "08:00";
2024-10-05 14:42:44 +02:00
mastodon = {
2024-10-05 14:42:44 +02:00
enable = true;
2024-10-05 15:09:11 +02:00
tokenFile = config.age.secrets.mastodon-token-smyth.path;
2024-10-05 14:42:44 +02:00
language = "en";
2024-10-05 14:42:44 +02:00
};
telegram = {
enable = true;
tokenFile = config.age.secrets.telegram-token-kmein.path;
2025-12-27 22:22:54 +01:00
chatIds = [ "@HerbertWeirSmyth" ];
2024-10-05 14:42:44 +02:00
};
2025-12-27 22:22:54 +01:00
command = toString (
pkgs.writers.writeDash "random-smyth" ''
set -efu
2022-08-23 14:47:24 +02:00
2025-12-27 22:22:54 +01:00
good_curl() {
${pkgs.curl}/bin/curl "$@" \
--compressed \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'DNT: 1' \
-H 'Connection: keep-alive' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Priority: u=0, i' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache'
}
2025-10-21 20:00:25 +02:00
2025-12-27 22:22:54 +01:00
RANDOM_SECTION=$(
good_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/"$//'
)
2022-08-23 14:47:24 +02:00
2025-12-27 22:22:54 +01:00
url="http://www.perseus.tufts.edu/hopper/text?doc=$RANDOM_SECTION"
good_curl -sSL "$url"\
| ${pkgs.htmlq}/bin/htmlq '#text_main' \
| ${pkgs.gnused}/bin/sed 's/<\/\?hr>//g' \
| ${pkgs.pandoc}/bin/pandoc -f html -t plain --wrap=none
2024-10-08 18:46:25 +02:00
2025-12-27 22:22:54 +01:00
printf '\n%s\n\n#AncientGreek' "$url"
''
);
2022-08-23 14:47:24 +02:00
};
2024-10-05 14:42:44 +02:00
systemd.timers.bot-smyth.timerConfig.RandomizedDelaySec = "10h";
2024-10-05 15:09:11 +02:00
age.secrets = {
mastodon-token-smyth.file = ../../secrets/mastodon-token-smyth.age;
};
2022-08-23 14:47:24 +02:00
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";
}
];
}