compsigh-minecraft/modules/discord.nix

59 lines
1.5 KiB
Nix

{ config, pkgs, ... }:
let
mcDataDir = "/srv/minecraft/data";
in
{
systemd.services.minecraft-discord-config = {
description = "Inject Discord bot token into Discord-MC-Chat config";
wantedBy = [ "multi-user.target" ];
before = [ "docker-minecraft.service" ];
after = [ "agenix.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = pkgs.writeShellScript "setup-discord-mc-chat" ''
set -euo pipefail
CONFIG_FILE="${mcDataDir}/config/discord-mc-chat.json"
mkdir -p "${mcDataDir}/config"
TOKEN=$(cat ${config.age.secrets.discord-bot-token.path})
# Admin Discord IDs: jet, z, edward
cat > "$CONFIG_FILE" <<EOF
{
"generic": {
"botToken": "$TOKEN",
"channelId": "1482269524571979899",
"consoleLogChannelId": "",
"updateNotificationChannelId": "",
"serverStatusVoiceChannelId": "",
"playerCountVoiceChannelId": "",
"useWebhook": true,
"updateChannelTopic": true,
"channelUpdateInterval": 300000,
"allowedMentions": ["users", "roles"],
"broadcastPlayerCommandExecution": false,
"announceServerStartStop": true,
"announcePlayerJoinLeave": true,
"announceDeathMessages": true,
"announceAdvancements": true,
"broadcastChatMessages": true,
"notifyUpdates": false,
"mentionAdminsForUpdates": false,
"adminsIds": [
"1008533670426050704",
"839601350865584158",
"373272898368176129"
]
},
"multiServer": {
"enable": false
}
}
EOF
chmod 600 "$CONFIG_FILE"
'';
};
};
}