mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
chore: format with alejandra
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
{ lib, config, pkgs, ... }:
|
||||
with lib;
|
||||
let
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.niveum.telegramBots;
|
||||
|
||||
botService = name: bot:
|
||||
@@ -8,37 +12,38 @@ let
|
||||
enable = bot.enable;
|
||||
startAt = bot.time;
|
||||
serviceConfig.Type = "oneshot";
|
||||
wants = [ "network-online.target" ];
|
||||
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}" \
|
||||
-d text="$QUOTE" ${
|
||||
lib.strings.optionalString (bot.parseMode != null)
|
||||
"-d parse_mode=${bot.parseMode}"
|
||||
}
|
||||
'') bot.chatIds
|
||||
++ [ "fi" ]);
|
||||
wants = ["network-online.target"];
|
||||
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}" \
|
||||
-d text="$QUOTE" ${
|
||||
lib.strings.optionalString (bot.parseMode != null)
|
||||
"-d parse_mode=${bot.parseMode}"
|
||||
}
|
||||
'')
|
||||
bot.chatIds
|
||||
++ ["fi"]);
|
||||
};
|
||||
in {
|
||||
options.niveum.telegramBots = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "Telegram bot";
|
||||
time = mkOption { type = types.str; };
|
||||
token = mkOption { type = types.strMatching "[0-9A-Za-z:-]+"; };
|
||||
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]+");
|
||||
};
|
||||
command = mkOption { type = types.str; };
|
||||
command = mkOption {type = types.str;};
|
||||
parseMode = mkOption {
|
||||
type = types.nullOr (types.enum [ "HTML" "Markdown" ]);
|
||||
type = types.nullOr (types.enum ["HTML" "Markdown"]);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
|
||||
config = { systemd.services = attrsets.mapAttrs' botService cfg; };
|
||||
config = {systemd.services = attrsets.mapAttrs' botService cfg;};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user