import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js"; import { handleAdminUserMap, handleAdminPollFixVoter, handleAdminPollShowEntry, } from "@subcommands/admin/userMap"; import { UpdatesCommands } from "@subcommands/admin/updates"; export function buildTgAdminCommand(): SlashCommandBuilder { const cmd = new SlashCommandBuilder() .setName("tg-admin") .setDescription("Administrative commands for TG bot management"); // ── user group ──────────────────────────────────────────────────────────────── cmd.addSubcommandGroup((g) => g .setName("user") .setDescription("Manage player registrations") .addSubcommand((s) => s .setName("map") .setDescription("Register a Discord user to a userKey") .addUserOption((o) => o .setName("user") .setDescription("Discord user to map") .setRequired(true) ) .addStringOption((o) => o .setName("userkey") .setDescription("The userKey to map this player to (must exist in characters.json)") .setRequired(true) .setAutocomplete(true) ) ) .addSubcommand((s) => s .setName("unmap") .setDescription("Remove a player's registration") .addUserOption((o) => o .setName("user") .setDescription("Discord user to unmap") .setRequired(true) ) ) .addSubcommand((s) => s .setName("list") .setDescription("List all registered player mappings") ) ); // ── poll group ───────────────────────────────────────────────────────────────── cmd.addSubcommandGroup((g) => g .setName("poll") .setDescription("Manage active poll entries") .addSubcommand((s) => s .setName("fix-voter") .setDescription("Re-resolve a voter's character in the active poll") .addUserOption((o) => o .setName("user") .setDescription("Discord user whose entry needs fixing") .setRequired(true) ) ) .addSubcommand((s) => s .setName("show-entry") .setDescription("Show raw poll entry for a user") .addUserOption((o) => o .setName("user") .setDescription("Discord user to inspect") .setRequired(true) ) ) ); cmd.addSubcommandGroup((g) => g .setName("updates") .setDescription("Manage update posts") .addSubcommand((s) => s .setName("post") .setDescription("Post or edit an update embed") .addStringOption((o) => o .setName("version") .setDescription("Version to post (defaults to latest)") .setRequired(false) .setAutocomplete(true) ) ) .addSubcommand((s) => s .setName("preview") .setDescription("Preview an update embed (ephemeral)") .addStringOption((o) => o .setName("version") .setDescription("Version to preview (defaults to latest)") .setRequired(false) .setAutocomplete(true) ) ) .addSubcommand((s) => s .setName("list") .setDescription("List all versions and their post status") ) ) return cmd; } export async function handleTgAdminCommand(interaction: ChatInputCommandInteraction): Promise { const group = interaction.options.getSubcommandGroup(true); const sub = interaction.options.getSubcommand(); if (group === "user") { if (sub === "map" || sub === "unmap" || sub === "list") { return handleAdminUserMap(interaction); } } if (group === "poll") { if (sub === "fix-voter") return handleAdminPollFixVoter(interaction); if (sub === "show-entry") return handleAdminPollShowEntry(interaction); } if (group === "updates") { if (sub === "post") return UpdatesCommands.post(interaction); if (sub === "preview") return UpdatesCommands.preview(interaction); if (sub === "list") return UpdatesCommands.list(interaction); } }