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

chore: nixfmt

This commit is contained in:
Kierán Meinhardt
2020-06-10 17:37:25 +02:00
parent 2c3957735b
commit d8a4d4eedf
90 changed files with 1461 additions and 985 deletions

View File

@@ -3,19 +3,22 @@ with lib;
let
cfg = config.niveum.telegramBots;
botService = name: bot: nameValuePair "telegram-bot-${name}" {
enable = bot.enable;
startAt = bot.time;
serviceConfig.Type = "oneshot";
wants = [ "network-online.target" ];
script = strings.concatStringsSep "\n" (["QUOTE=$(${bot.command})"] ++ 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);
};
botService = name: bot:
nameValuePair "telegram-bot-${name}" {
enable = bot.enable;
startAt = bot.time;
serviceConfig.Type = "oneshot";
wants = [ "network-online.target" ];
script = strings.concatStringsSep "\n" ([ "QUOTE=$(${bot.command})" ]
++ 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);
};
in {
options.niveum.telegramBots = mkOption {
type = types.attrsOf (types.submodule {
@@ -23,18 +26,18 @@ in {
enable = mkEnableOption "Telegram bot";
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]+"); };
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"]);
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; };
}