diff --git a/src/modals/report-message.ts b/src/modals/report-message.ts index 4559169..aef683c 100644 --- a/src/modals/report-message.ts +++ b/src/modals/report-message.ts @@ -1,7 +1,7 @@ import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, Client, EmbedBuilder, GuildTextBasedChannel, MessageFlags, ModalSubmitInteraction } from 'discord.js'; import { Database } from '../shared/Database'; -import { canOpenPrivateHelpTicket, createPrivateHelpTicketThread } from '../utils'; import { Modal } from '../types'; +import { canOpenPrivateHelpTicket, createPrivateHelpTicketThread } from '../utils'; class ReportMessageModal implements Modal { id = 'report-message'; @@ -96,4 +96,6 @@ class ReportMessageModal implements Modal { await interaction.editReply({ content: error.message }).catch(() => {}); } } -} \ No newline at end of file +} + +export default new ReportMessageModal(); \ No newline at end of file diff --git a/src/modals/sync-name-modal.ts b/src/modals/sync-name-modal.ts index 12af741..0f49dd4 100644 --- a/src/modals/sync-name-modal.ts +++ b/src/modals/sync-name-modal.ts @@ -1,32 +1,27 @@ import { Client, ModalSubmitInteraction } from 'discord.js'; -import { config } from '../config'; +import { Modal } from '../types'; import { deferInteraction, syncName } from '../utils'; -export default { - name: 'sync-name-modal', - handler: async function (client: Client, interaction: ModalSubmitInteraction, id: string) { +class SyncNameModal implements Modal { + id = 'sync-name-modal'; + + async execute(context: Client, interaction: ModalSubmitInteraction, id: string): Promise { + if (!interaction.inGuild()) return; await deferInteraction(interaction); - const e621Id = Number(interaction.fields.getTextInputValue('id') ?? 0); + try { + const e621Id = Number(interaction.fields.getTextInputValue('id') ?? 0); + if (isNaN(e621Id)) throw new Error('Provided id is not a number.'); - if (isNaN(e621Id)) return await interaction.editReply('Provided id is not a number'); + const guild = await context.guilds.fetch(interaction.guildId); + const member = await guild.members.fetch(id); + if (!member) throw new Error('Unable to fetch the target member.'); - const member = await interaction.guild?.members.fetch(id); - - if (!member) { - return interaction.editReply('An error has occurred. Please try again later.'); + await syncName(interaction, member, e621Id); + } catch (error: Error | any) { + await interaction.editReply({ content: error.message }).catch(() => {}); } - - const guild = await interaction.client.guilds.fetch(config.DISCORD_GUILD_ID!); - - if (!guild) { - return interaction.editReply('An error has occurred. Please try again later.'); - } - - if (!guild.members.me) { - return interaction.editReply('An error has occurred. Please try again later.'); - } - - await syncName(interaction, member, e621Id); } -}; \ No newline at end of file +} + +export default new SyncNameModal(); \ No newline at end of file