mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
bots: post on mastodon as well
This commit is contained in:
@@ -41,18 +41,24 @@
|
||||
'
|
||||
'';
|
||||
in {
|
||||
niveum.telegramBots.transits = {
|
||||
niveum.bots.transits = {
|
||||
enable = true;
|
||||
time = "*:0/1";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["-1001796440545"];
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["-1001796440545"];
|
||||
};
|
||||
command = toString (pkgs.writers.writeDash "common-transits" ''
|
||||
set -efu
|
||||
|
||||
now=$(${pkgs.coreutils}/bin/date +%_H:%M | ${pkgs.gnused}/bin/sed 's/^\s*//')
|
||||
date=$(${pkgs.coreutils}/bin/date +'%m %d %Y')
|
||||
{
|
||||
${pkgs.astrolog}/bin/astrolog -qd $date -zN Berlin -Yt -Yd -d -R Uranus Neptune Pluto "North Node" -A 2
|
||||
${pkgs.astrolog}/bin/astrolog -Yt -Yd -q 10 22 1999 6:32 -zN Kassel -td $date -R Uranus Neptune Pluto "North Node"
|
||||
} | ${toSymbols} | ${pkgs.coreutils}/bin/sort -n | ${pkgs.gnugrep}/bin/grep "^$now" || :
|
||||
(
|
||||
cd ${pkgs.astrolog}/bin
|
||||
./astrolog -qd $date -zN Berlin -Yt -Yd -d -R Uranus Neptune Pluto "North Node" -A 2
|
||||
./astrolog -Yt -Yd -q 10 22 1999 6:32 -zN Kassel -td $date -R Uranus Neptune Pluto "North Node"
|
||||
) | ${toSymbols} | ${pkgs.coreutils}/bin/sort -n | ${pkgs.gnugrep}/bin/grep "^$now" || :
|
||||
'');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,12 +13,19 @@
|
||||
autorenkalender =
|
||||
pkgs.python3Packages.callPackage autorenkalender-package {};
|
||||
in {
|
||||
niveum.telegramBots.autorenkalender = {
|
||||
niveum.bots.autorenkalender = {
|
||||
enable = true;
|
||||
time = "07:00";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@autorenkalender"];
|
||||
parseMode = "Markdown";
|
||||
mastodon = {
|
||||
enable = false;
|
||||
language = "de";
|
||||
};
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@autorenkalender"];
|
||||
parseMode = "Markdown";
|
||||
};
|
||||
command = "${autorenkalender}/bin/autorenkalender";
|
||||
};
|
||||
|
||||
|
||||
@@ -9,22 +9,49 @@
|
||||
sha256 = "sha256-nA+EwAH2vkeolsy9AoPLEMt1uGKDZe/aPrS95CZvuus=";
|
||||
};
|
||||
in {
|
||||
niveum.telegramBots.celan = {
|
||||
niveum.bots.celan = {
|
||||
enable = true;
|
||||
time = "08:00";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@PaulCelan"];
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@PaulCelan"];
|
||||
};
|
||||
mastodon = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.mastodon-token-celan.path;
|
||||
language = "de";
|
||||
};
|
||||
command = toString (pkgs.writers.writeDash "random-celan" ''
|
||||
cd ${celan}
|
||||
poem="$(${pkgs.findutils}/bin/find . -type f | ${pkgs.coreutils}/bin/shuf -n1)"
|
||||
source="$(${pkgs.coreutils}/bin/dirname "$poem" | ${pkgs.gnused}/bin/sed 's#^\./##;s/[-_]/ /g;s!/! › !g;s/0\([0-9]\+\)/\1/g')"
|
||||
source="$(${pkgs.coreutils}/bin/dirname "$poem" \
|
||||
| ${pkgs.gnused}/bin/sed 's#^\./##;s/[-_]/ /g;s!/! › !g;s/0\([0-9]\+\)/\1/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Der Sand aus den Urnen/#Der_Sand_aus_den_Urnen (1948)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Mohn und Gedächtnis/#Mohn_und_Gedächtnis (1952)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Von Schwelle zu Schwelle/#Von_Schwelle_zu_Schwelle (1955)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Sprachgitter/#& (1959)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Niemandsrose/#& (1963)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Atemwende/#& (1967)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Fadensonnen/#& (1968)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Lichtzwang/#& (1970)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Schneepart/#& (1971)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Zeitgehöft/#& (1976)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Frühwerk/#& (1989)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Eingedunkelt/#& (1991)/g' \
|
||||
| ${pkgs.gnused}/bin/sed 's/Nachlaß/#& (1997)/g'
|
||||
)"
|
||||
cat "$poem"
|
||||
echo
|
||||
printf "Aus: %s\n" "$source"
|
||||
printf "Aus: %s\n\n#PaulCelan #Celan #Lyrik #poetry" "$source"
|
||||
'');
|
||||
};
|
||||
|
||||
systemd.timers.telegram-bot-celan.timerConfig.RandomizedDelaySec = "10h";
|
||||
age.secrets = {
|
||||
mastodon-token-celan.file = ../../secrets/mastodon-token-celan.age;
|
||||
};
|
||||
|
||||
systemd.timers.bot-celan.timerConfig.RandomizedDelaySec = "10h";
|
||||
|
||||
niveum.passport.services = [
|
||||
{
|
||||
|
||||
@@ -7,15 +7,22 @@
|
||||
}: let
|
||||
hesychius = inputs.scripts.outPath + "/hesychius/hesychius.txt";
|
||||
in {
|
||||
niveum.telegramBots.hesychius = {
|
||||
niveum.bots.hesychius = {
|
||||
enable = true;
|
||||
time = "08:00";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@HesychiosAlexandreus"];
|
||||
mastodon = {
|
||||
enable = false;
|
||||
language = "el";
|
||||
};
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@HesychiosAlexandreus"];
|
||||
};
|
||||
command = "${pkgs.coreutils}/bin/shuf -n1 ${hesychius}";
|
||||
};
|
||||
|
||||
systemd.timers.telegram-bot-hesychius.timerConfig.RandomizedDelaySec = "10h";
|
||||
systemd.timers.bot-hesychius.timerConfig.RandomizedDelaySec = "10h";
|
||||
|
||||
niveum.passport.services = [
|
||||
{
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
niveumPackages,
|
||||
...
|
||||
}: {
|
||||
niveum.telegramBots.quotebot = {
|
||||
niveum.bots.quotebot = {
|
||||
enable = true;
|
||||
time = "08/6:00";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["-1001760262519"];
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["-1001760262519"];
|
||||
parseMode = "Markdown";
|
||||
};
|
||||
command = "${niveumPackages.literature-quote}/bin/literature-quote";
|
||||
parseMode = "Markdown";
|
||||
};
|
||||
|
||||
niveum.passport.services = [
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
niveum.telegramBots.smyth = {
|
||||
niveum.bots.smyth = {
|
||||
enable = true;
|
||||
time = "08:00";
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@HerbertWeirSmyth"];
|
||||
mastodon = {
|
||||
enable = false;
|
||||
language = "en";
|
||||
};
|
||||
telegram = {
|
||||
enable = true;
|
||||
tokenFile = config.age.secrets.telegram-token-kmein.path;
|
||||
chatIds = ["@HerbertWeirSmyth"];
|
||||
};
|
||||
command = toString (pkgs.writers.writeDash "random-smyth" ''
|
||||
set -efu
|
||||
|
||||
@@ -26,7 +33,7 @@
|
||||
'');
|
||||
};
|
||||
|
||||
systemd.timers.telegram-bot-smyth.timerConfig.RandomizedDelaySec = "10h";
|
||||
systemd.timers.bot-smyth.timerConfig.RandomizedDelaySec = "10h";
|
||||
|
||||
niveum.passport.services = [
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
niveumPackages,
|
||||
...
|
||||
}: {
|
||||
systemd.services.telegram-bot-tlg-wotd = {
|
||||
systemd.services.bot-tlg-wotd = {
|
||||
enable = true;
|
||||
wants = ["network-online.target"];
|
||||
startAt = "9:30";
|
||||
@@ -29,10 +29,16 @@
|
||||
definition=$(echo "$json_data" | jq -r '.definition | sub("<.*>"; "") | rtrimstr(" ")')
|
||||
first_occurrence=$(echo "$json_data" | jq -r '.firstOccurrence')
|
||||
total_occurrences=$(echo "$json_data" | jq -r '.totalOccurrences')
|
||||
caption="*$word* ‘$definition’
|
||||
telegram_caption="*$word* ‘$definition’
|
||||
|
||||
First occurrence (century): $first_occurrence
|
||||
Number of occurrences (in all Ancient Greek texts): $total_occurrences"
|
||||
mastodon_caption="$word ‘$definition’
|
||||
|
||||
First occurrence (century): $first_occurrence
|
||||
Number of occurrences (in all Ancient Greek texts): $total_occurrences"
|
||||
|
||||
#ancientgreek #classics #wotd #wordoftheday
|
||||
|
||||
transliteration=$(${pkgs.writers.writePython3 "translit.py" {
|
||||
libraries = [ niveumPackages.cltk ];
|
||||
@@ -105,16 +111,16 @@
|
||||
-annotate +100+120 "‘$definition’" \
|
||||
-fill "$color2" \
|
||||
-pointsize 40 -gravity southwest \
|
||||
-annotate +100+60 "t.me/TLGWotD" \
|
||||
-annotate +100+60 "attested $total_occurrences times" \
|
||||
-pointsize 40 -gravity southeast \
|
||||
-annotate +100+60 "$(date -I)" \
|
||||
"$photo_path"
|
||||
|
||||
curl -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" \
|
||||
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendPhoto" \
|
||||
-F "chat_id=\"$chat_id\"" \
|
||||
-F "photo=@$photo_path" \
|
||||
-F parse_mode=Markdown \
|
||||
-F caption="$caption"
|
||||
-F caption="$telegram_caption"
|
||||
|
||||
mastodon_upload_response=$(curl -X POST "https://botsin.space/api/v2/media" \
|
||||
-H "Authorization: Bearer $MASTODON_TOKEN" \
|
||||
@@ -123,7 +129,8 @@
|
||||
mastodon_image_id=$(echo $mastodon_upload_response | jq -r .id)
|
||||
curl -X POST "https://botsin.space/api/v1/statuses" \
|
||||
-H "Authorization: Bearer $MASTODON_TOKEN" \
|
||||
-d "status=$caption" \
|
||||
-d "status=$mastodon_caption" \
|
||||
-d "visibility=public" \
|
||||
-d "media_ids[]=$mastodon_image_id"
|
||||
'';
|
||||
serviceConfig = {
|
||||
|
||||
@@ -5,48 +5,89 @@
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.niveum.telegramBots;
|
||||
cfg = config.niveum.bots;
|
||||
|
||||
botService = name: bot:
|
||||
nameValuePair "telegram-bot-${name}" {
|
||||
nameValuePair "bot-${name}" {
|
||||
enable = bot.enable;
|
||||
startAt = bot.time;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
LoadCredential = "token:${bot.tokenFile}";
|
||||
LoadCredential = lib.optionals (bot.telegram.enable) [
|
||||
"telegram-token:${bot.telegram.tokenFile}"
|
||||
] ++ lib.optionals (bot.mastodon.enable) [
|
||||
"mastodon-token:${bot.mastodon.tokenFile}"
|
||||
];
|
||||
};
|
||||
wants = ["network-online.target"];
|
||||
script = ''
|
||||
export TOKEN="$(cat "$CREDENTIALS_DIRECTORY/token")"
|
||||
QUOTE=$(${bot.command})
|
||||
if [ -n "$QUOTE" ]; then
|
||||
echo $QUOTE >&2
|
||||
${strings.concatStringsSep "\n" (map (chatId: ''
|
||||
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/bot''${TOKEN}/sendMessage" \
|
||||
-d chat_id="${chatId}" \
|
||||
-d text="$QUOTE" ${
|
||||
lib.strings.optionalString (bot.parseMode != null)
|
||||
"-d parse_mode=${bot.parseMode}"
|
||||
} | ${pkgs.jq}/bin/jq -e .ok
|
||||
'')
|
||||
bot.chatIds)}
|
||||
|
||||
${lib.optionalString (bot.mastodon.enable) ''
|
||||
export MASTODON_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/mastodon-token")"
|
||||
${pkgs.curl}/bin/curl -X POST "https://${bot.mastodon.homeserver}/api/v1/statuses" \
|
||||
-H "Authorization: Bearer $MASTODON_TOKEN" \
|
||||
-d status="$QUOTE" \
|
||||
-d "language=${bot.mastodon.language}" \
|
||||
-d "visibility=public"
|
||||
''}
|
||||
|
||||
${lib.optionalString (bot.telegram.enable) ''
|
||||
export TELEGRAM_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/telegram-token")"
|
||||
${strings.concatStringsSep "\n" (map (chatId: ''
|
||||
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/bot''${TELEGRAM_TOKEN}/sendMessage" \
|
||||
-d chat_id="${chatId}" \
|
||||
-d text="$QUOTE" ${
|
||||
lib.strings.optionalString (bot.telegram.parseMode != null)
|
||||
"-d parse_mode=${bot.telegram.parseMode}"
|
||||
} | ${pkgs.jq}/bin/jq -e .ok
|
||||
'')
|
||||
bot.telegram.chatIds)}
|
||||
''}
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in {
|
||||
options.niveum.telegramBots = mkOption {
|
||||
options.niveum.bots = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "Telegram bot";
|
||||
enable = mkEnableOption "Mastodon and Telegram bot";
|
||||
time = mkOption {type = types.str;};
|
||||
tokenFile = mkOption {type = types.path;};
|
||||
chatIds = mkOption {
|
||||
type = types.listOf (types.strMatching "-?[0-9]+|@[A-Za-z0-9]+");
|
||||
};
|
||||
command = mkOption {type = types.str;};
|
||||
parseMode = mkOption {
|
||||
type = types.nullOr (types.enum ["HTML" "Markdown"]);
|
||||
default = null;
|
||||
mastodon = mkOption {
|
||||
default = {};
|
||||
type = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "Posting to Mastodon";
|
||||
language = mkOption {
|
||||
type = types.str;
|
||||
default = "en";
|
||||
};
|
||||
tokenFile = mkOption {type = types.path;};
|
||||
homeserver = mkOption {
|
||||
type = types.str;
|
||||
default = "botsin.space";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
telegram = mkOption {
|
||||
default = {};
|
||||
type = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "Posting to Telegram";
|
||||
tokenFile = mkOption {type = types.path;};
|
||||
chatIds = mkOption {
|
||||
type = types.listOf (types.strMatching "-?[0-9]+|@[A-Za-z0-9]+");
|
||||
};
|
||||
parseMode = mkOption {
|
||||
type = types.nullOr (types.enum ["HTML" "Markdown"]);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
2
secrets
2
secrets
Submodule secrets updated: c1618c86c3...c819d0180b
Reference in New Issue
Block a user