mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(modals): Implement sync-name-modal modal.
This commit is contained in:
@@ -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';
|
||||||
@@ -96,4 +96,6 @@ class ReportMessageModal implements Modal<Client> {
|
|||||||
await interaction.editReply({ content: error.message }).catch(() => {});
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default new ReportMessageModal();
|
||||||
@@ -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);
|
||||||
|
|
||||||
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);
|
await syncName(interaction, member, e621Id);
|
||||||
|
} catch (error: Error | any) {
|
||||||
if (!member) {
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export default new SyncNameModal();
|
||||||
Reference in New Issue
Block a user