(modals): Implement sync-name-modal modal.

This commit is contained in:
2026-10-14 18:10:56 +08:00
parent 99fd6403a2
commit 63152ffaf5
2 changed files with 22 additions and 25 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, Client, EmbedBuilder, GuildTextBasedChannel, MessageFlags, ModalSubmitInteraction } from 'discord.js'; import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, Client, EmbedBuilder, GuildTextBasedChannel, MessageFlags, ModalSubmitInteraction } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { canOpenPrivateHelpTicket, createPrivateHelpTicketThread } from '../utils';
import { Modal } from '../types'; import { Modal } from '../types';
import { canOpenPrivateHelpTicket, createPrivateHelpTicketThread } from '../utils';
class ReportMessageModal implements Modal<Client> { class ReportMessageModal implements Modal<Client> {
id = 'report-message'; id = 'report-message';
@@ -97,3 +97,5 @@ class ReportMessageModal implements Modal<Client> {
} }
} }
} }
export default new ReportMessageModal();
+17 -22
View File
@@ -1,32 +1,27 @@
import { Client, ModalSubmitInteraction } from 'discord.js'; import { Client, ModalSubmitInteraction } from 'discord.js';
import { config } from '../config'; import { Modal } from '../types';
import { deferInteraction, syncName } from '../utils'; import { deferInteraction, syncName } from '../utils';
export default { class SyncNameModal implements Modal<Client> {
name: 'sync-name-modal', id = 'sync-name-modal';
handler: async function (client: Client, interaction: ModalSubmitInteraction, id: string) {
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction, id: string): Promise<void> {
if (!interaction.inGuild()) return;
await deferInteraction(interaction); await deferInteraction(interaction);
try {
const e621Id = Number(interaction.fields.getTextInputValue('id') ?? 0); 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);
const member = await interaction.guild?.members.fetch(id); if (!member) throw new Error('Unable to fetch the target member.');
if (!member) {
return interaction.editReply('An error has occurred. Please try again later.');
}
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); await syncName(interaction, member, e621Id);
} catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {});
} }
}; }
}
export default new SyncNameModal();