diff --git a/src/client/KordClient.ts b/src/client/KordClient.ts index 135eeab..931d9a0 100644 --- a/src/client/KordClient.ts +++ b/src/client/KordClient.ts @@ -17,6 +17,7 @@ export class KordClient extends Client { GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildInvites, + GatewayIntentBits.GuildMembers, ], partials: [Partials.Message, Partials.Channel, Partials.GuildMember], }); diff --git a/src/commands/autorole.ts b/src/commands/autorole.ts index 7e4cd63..488e50f 100644 --- a/src/commands/autorole.ts +++ b/src/commands/autorole.ts @@ -50,14 +50,26 @@ class AutoRoleCommand extends Command { name: t(locale, 'commands.autorole.statusLabel'), value: config?.isEnabled ? `✅ ${t(locale, 'commands.autorole.enabled')}` : `❌ ${t(locale, 'commands.autorole.disabled')}`, inline: true + }, + { + name: t(locale, 'commands.autorole.botStatusLabel'), + value: config?.botEnabled ? `✅ ${t(locale, 'commands.autorole.enabled')}` : `❌ ${t(locale, 'commands.autorole.disabled')}`, + inline: true } ); const row1 = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId('autorole_toggle') - .setLabel(config?.isEnabled ? t(locale, 'commands.autorole.disabled') : t(locale, 'commands.autorole.enabled')) + .setLabel(t(locale, 'commands.autorole.statusLabel')) .setStyle(config?.isEnabled ? ButtonStyle.Danger : ButtonStyle.Success), + new ButtonBuilder() + .setCustomId('autorole_toggle_bot') + .setLabel(t(locale, 'commands.autorole.botStatusLabel')) + .setStyle(config?.botEnabled ? ButtonStyle.Danger : ButtonStyle.Success) + ); + + const row2 = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId('autorole_set_user') .setLabel(t(locale, 'commands.autorole.userRoleLabel')) @@ -68,7 +80,7 @@ class AutoRoleCommand extends Command { .setStyle(ButtonStyle.Primary) ); - const row2 = new ActionRowBuilder().addComponents( + const row3 = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId('autorole_retroactive') .setLabel(t(locale, 'commands.autorole.retroactiveBtn')) @@ -80,40 +92,11 @@ class AutoRoleCommand extends Command { .setStyle(ButtonStyle.Secondary) ); - const response = await interaction.reply({ + await interaction.reply({ embeds: [embed], - components: [row1, row2], + components: [row1, row2, row3], ephemeral: true, }); - - const collector = response.createMessageComponentCollector({ - componentType: ComponentType.Button, - time: 300000, // 5분 - }); - - collector.on('collect', async (i) => { - if (i.customId === 'autorole_toggle') { - const newEnabled = !config?.isEnabled; - await autoRoleService.setEnabled(guild.id, newEnabled); - await i.update({ content: t(locale, 'commands.autorole.updateSuccess'), embeds: [], components: [] }); - collector.stop(); - } else if (i.customId === 'autorole_set_user' || i.customId === 'autorole_set_bot') { - const isBot = i.customId === 'autorole_set_bot'; - const roleSelect = new RoleSelectMenuBuilder() - .setCustomId(`autorole_select_${isBot ? 'bot' : 'user'}`) - .setPlaceholder(isBot ? t(locale, 'commands.autorole.botRoleLabel') : t(locale, 'commands.autorole.userRoleLabel')) - .setMaxValues(1); - - const selectRow = new ActionRowBuilder().addComponents(roleSelect); - await i.update({ components: [selectRow] }); - } else if (i.customId === 'autorole_retroactive') { - if (!config?.userRoleId) return; - await autoRoleService.applyRetroactively(guild, config.userRoleId, i.user.id); - await i.update({ content: t(locale, 'commands.autorole.retroactiveStarted'), embeds: [], components: [] }); - collector.stop(); - } - // exclude 등 추가 인터랙션 구현 예정 - }); } } diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 663a3a9..af9a8ff 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -143,6 +143,66 @@ export default { }, locale); } } + else if (interaction.isButton() && interaction.customId.startsWith('autorole_')) { + const locale = await getInteractionLocale(interaction); + const { autoRoleService } = require('../services/AutoRoleService'); + await withErrorHandler(interaction, async () => { + // 타임아웃 방지를 위해 즉시 승인 + await interaction.deferUpdate(); + + const guild = interaction.guild!; + if (interaction.customId === 'autorole_toggle') { + const config = await autoRoleService.getConfig(guild.id); + const newEnabled = !config?.isEnabled; + await autoRoleService.setEnabled(guild.id, newEnabled); + await interaction.editReply({ content: t(locale, 'commands.autorole.updateSuccess'), embeds: [], components: [] }); + } else if (interaction.customId === 'autorole_toggle_bot') { + const config = await autoRoleService.getConfig(guild.id); + const newBotEnabled = !config?.botEnabled; + await autoRoleService.updateConfig(guild.id, { botEnabled: newBotEnabled }); + await interaction.editReply({ content: t(locale, 'commands.autorole.updateSuccess'), embeds: [], components: [] }); + } else if (interaction.customId === 'autorole_retroactive') { + const config = await autoRoleService.getConfig(guild.id); + if (config?.userRoleId) { + await autoRoleService.applyRetroactively(guild, config.userRoleId, interaction.user.id); + await interaction.editReply({ content: t(locale, 'commands.autorole.retroactiveStarted'), embeds: [], components: [] }); + } + } else if (interaction.customId === 'autorole_set_user' || interaction.customId === 'autorole_set_bot') { + const isBot = interaction.customId === 'autorole_set_bot'; + const { RoleSelectMenuBuilder } = require('discord.js'); + const roleSelect = new RoleSelectMenuBuilder() + .setCustomId(`autorole_select_${isBot ? 'bot' : 'user'}`) + .setPlaceholder(isBot ? t(locale, 'commands.autorole.botRoleLabel') : t(locale, 'commands.autorole.userRoleLabel')) + .setMaxValues(1); + + const selectRow = new ActionRowBuilder().addComponents(roleSelect); + await interaction.editReply({ components: [selectRow] }); + } + // 나머지 버튼 처리 + }, locale); + } + else if (interaction.isRoleSelectMenu() && interaction.customId.startsWith('autorole_select_')) { + const locale = await getInteractionLocale(interaction); + const { autoRoleService } = require('../services/AutoRoleService'); + await withErrorHandler(interaction, async () => { + // 타임아웃 방지를 위해 즉시 승인 + await interaction.deferUpdate(); + + const guild = interaction.guild!; + const isBot = interaction.customId.includes('bot'); + const roleId = interaction.values[0]; + + await autoRoleService.updateConfig(guild.id, { + [isBot ? 'botRoleId' : 'userRoleId']: roleId + }); + + await interaction.editReply({ + content: t(locale, 'commands.autorole.updateSuccess'), + embeds: [], + components: [] + }); + }, locale); + } else if (interaction.isModalSubmit()) { const customId = interaction.customId; if (customId.startsWith('modal_vc_')) {