(modals): Implement open-ticket-modal modal.

This commit is contained in:
2026-10-14 16:19:27 +08:00
parent 741b56a3dd
commit a996947157
4 changed files with 24 additions and 16 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ class AddKnowledgebaseItemModal implements Modal<Client> {
}); });
await Database.addToKnowledgebase(interaction.guildId, name, content); await Database.addToKnowledgebase(interaction.guildId, name, content);
await interaction.editReply(`\`${name}\` has been added to the knowledgebase.`); await interaction.editReply({ content: `\`${name}\` has been added to the knowledgebase.` });
} catch (error: Error | any) { } catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {}); await interaction.editReply({ content: error.message }).catch(() => {});
} }
+1 -1
View File
@@ -32,7 +32,7 @@ class EditKnowledgebaseItemModal implements Modal<Client> {
}); });
await Database.editKnowledgebaseItem(id, content); await Database.editKnowledgebaseItem(id, content);
await interaction.editReply(`\`${existing.name}\` has been edited.`); await interaction.editReply({ content: `\`${existing.name}\` has been edited.` });
} catch (error: Error | any) { } catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {}); await interaction.editReply({ content: error.message }).catch(() => {});
} }
+1 -1
View File
@@ -1,7 +1,7 @@
import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js'; import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { createPrivateHelpTicketThread } from '../utils';
import { Modal } from '../types'; import { Modal } from '../types';
import { createPrivateHelpTicketThread } from '../utils';
const warning = '\n\n\nLeaving this thread without acknowledgement may result in punishment. Staff will close the thread when they deem your response acceptable.'; const warning = '\n\n\nLeaving this thread without acknowledgement may result in punishment. Staff will close the thread when they deem your response acceptable.';
+21 -13
View File
@@ -1,23 +1,31 @@
import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js'; import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { Modal } from '../types';
import { createPrivateHelpTicketThread } from '../utils'; import { createPrivateHelpTicketThread } from '../utils';
export default { class OpenTicketModal implements Modal<Client> {
name: 'open-ticket-modal', id = 'open-ticket-modal';
handler: async function (client: Client, interaction: ModalSubmitInteraction) {
const guild = await client.guilds.fetch(interaction.guildId!);
const member = await guild.members.fetch(interaction.user.id);
const guildSettings = await Database.getOrCreateSettings(guild.id); async execute(context: Client<boolean>, interaction: ModalSubmitInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
if (!guildSettings || !guildSettings.private_help_role_id) try {
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket. Please report this to a staff member.' }); const guild = await context.guilds.fetch(interaction.guildId!);
const member = await guild.members.fetch(interaction.user.id);
const reason = interaction.fields.getTextInputValue('ticket-message'); const settings = await Database.getOrCreateSettings(interaction.guildId);
if (settings.private_help_role_id) throw new Error("`private_help_role_id` hasn't been configured. Please report this error to staff.");
const thread = await createPrivateHelpTicketThread(client, guild, member, reason); const reason = interaction.fields.getTextInputValue('ticket-message');
const thread = await createPrivateHelpTicketThread(context, guild, member, reason);
if (!thread) throw new Error('Failed to create ticket. Please report this to a staff member.');
if (thread) interaction.reply({ flags: [MessageFlags.Ephemeral], content: `Your ticket has been created: ${thread}` }); await interaction.editReply({ content: `Your ticket has been created: ${thread}` });
else interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket. Please report this to a staff member.' }); } catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {});
}
} }
}; }
export default new OpenTicketModal();