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

feat: astro telegram bot sends live updates

This commit is contained in:
2022-01-05 16:40:34 +01:00
parent 5051938679
commit 0656b0eaa3
2 changed files with 8 additions and 6 deletions

View File

@@ -40,15 +40,16 @@ let
in {
niveum.telegramBots.transits = {
enable = true;
time = "0:00";
time = "*:0/1";
token = lib.strings.fileContents <system-secrets/telegram/kmein.token>;
chatIds = [ "-1001796440545" ];
command = toString (pkgs.writers.writeDash "common-transits" ''
now=$(${pkgs.coreutils}/bin/date +%_H:%M | ${pkgs.gnused}/bin/sed 's/^\s*//')
date=$(${pkgs.coreutils}/bin/date +'%m %d %Y')
{
date=$(${pkgs.coreutils}/bin/date +'%m %d %Y')
${nixpkgs-unstable.astrolog}/bin/astrolog -qd $date -zN Berlin -Yt -Yd -d -R Uranus Neptune Pluto
${nixpkgs-unstable.astrolog}/bin/astrolog -Yt -Yd -q 10 22 1999 6:32 -zN Kassel -td $date -R Uranus Neptune Pluto
} | ${toSymbols} | ${pkgs.coreutils}/bin/sort -n
} | ${toSymbols} | ${pkgs.coreutils}/bin/sort -n | ${pkgs.gnugrep}/bin/grep "^$now" || :
'');
};
}

View File

@@ -9,7 +9,7 @@ let
startAt = bot.time;
serviceConfig.Type = "oneshot";
wants = [ "network-online.target" ];
script = strings.concatStringsSep "\n" ([ "QUOTE=$(${bot.command})" ]
script = strings.concatStringsSep "\n" ([ "QUOTE=$(${bot.command})" "if [ -n \"$QUOTE\" ]; then" ]
++ map (chatId: ''
${pkgs.curl}/bin/curl -s -X POST "https://api.telegram.org/bot${bot.token}/sendMessage" \
-d chat_id="${chatId}" \
@@ -17,7 +17,8 @@ let
lib.strings.optionalString (bot.parseMode != null)
"-d parse_mode=${bot.parseMode}"
}
'') bot.chatIds);
'') bot.chatIds
++ [ "fi" ]);
};
in {
options.niveum.telegramBots = mkOption {
@@ -27,7 +28,7 @@ in {
time = mkOption { type = types.str; };
token = mkOption { type = types.strMatching "[0-9A-Za-z:-]+"; };
chatIds = mkOption {
type = types.listOf (types.strMatching "[0-9]+|@[A-Za-z0-9]+");
type = types.listOf (types.strMatching "-?[0-9]+|@[A-Za-z0-9]+");
};
command = mkOption { type = types.str; };
parseMode = mkOption {