(interaction)
| 61 | category: 'Fun', |
| 62 | |
| 63 | async execute(interaction) { |
| 64 | try { |
| 65 | const deferSuccess = await InteractionHelper.safeDefer(interaction, { flags: MessageFlags.Ephemeral }); |
| 66 | if (!deferSuccess) { |
| 67 | logger.warn('Count command defer failed', { userId: interaction.user.id, guildId: interaction.guildId }); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)) { |
| 72 | return await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need the **Manage Server** permission to use this command.' }); |
| 73 | } |
| 74 | |
| 75 | const guildId = interaction.guildId; |
| 76 | const subcommand = interaction.options.getSubcommand(); |
| 77 | const config = await getCountingGameConfig(interaction.client, guildId); |
| 78 | |
| 79 | if (subcommand === 'setup') { |
| 80 | const channel = interaction.options.getChannel('channel'); |
| 81 | const system = interaction.options.getString('system'); |
| 82 | if (!channel || channel.type !== ChannelType.GuildText) { |
| 83 | return await replyUserError(interaction, { type: ErrorTypes.VALIDATION, message: 'Please choose a text channel for the counting game.' }); |
| 84 | } |
| 85 | |
| 86 | if (config.enabled && config.channelId && config.channelId !== channel.id) { |
| 87 | return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'This server already has an active counting channel configured: <#${config.channelId}>. Disable the current counting game first, or use that existing channel.' }); |
| 88 | } |
| 89 | |
| 90 | await activateCountingGame(interaction.client, guildId, channel.id, system); |
| 91 | return await InteractionHelper.safeEditReply(interaction, { |
| 92 | embeds: [ |
| 93 | successEmbed( |
| 94 | 'Counting Game Enabled', |
| 95 | `The counting game is now active in ${channel} using the **${getCountingSystemLabel(system)}** system. Players must count up from **1** and may not post two numbers in a row.`, |
| 96 | ), |
| 97 | ], |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | if (subcommand === 'disable') { |
| 102 | if (!config.enabled) { |
| 103 | return await InteractionHelper.safeEditReply(interaction, { |
| 104 | embeds: [infoEmbed('Counting Game Disabled', 'The counting game is already disabled for this server.')], |
| 105 | }); |
| 106 | } |
| 107 | |
| 108 | await disableCountingGame(interaction.client, guildId); |
| 109 | return await InteractionHelper.safeEditReply(interaction, { |
| 110 | embeds: [successEmbed('Counting Game Disabled', 'The counting game has been disabled.')], |
| 111 | }); |
| 112 | } |
| 113 | |
| 114 | if (subcommand === 'status') { |
| 115 | const fields = [ |
| 116 | { name: 'Enabled', value: config.enabled ? 'Yes' : 'No', inline: true }, |
| 117 | { name: 'Channel', value: config.channelId ? `<#${config.channelId}>` : 'Not configured', inline: true }, |
| 118 | { name: 'System', value: getCountingSystemLabel(config.system), inline: true }, |
| 119 | { name: 'Next count', value: getExpectedCountValue(config), inline: true }, |
| 120 | { name: 'Current streak', value: `${config.currentStreak}`, inline: true }, |
nothing calls this directly
no test coverage detected