mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(modals): Implement open-ticket-modal modal.
This commit is contained in:
@@ -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(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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.';
|
||||||
|
|
||||||
|
|||||||
@@ -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!);
|
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId!);
|
||||||
const member = await guild.members.fetch(interaction.user.id);
|
const member = await guild.members.fetch(interaction.user.id);
|
||||||
|
|
||||||
const guildSettings = await Database.getOrCreateSettings(guild.id);
|
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.");
|
||||||
if (!guildSettings || !guildSettings.private_help_role_id)
|
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket. Please report this to a staff member.' });
|
|
||||||
|
|
||||||
const reason = interaction.fields.getTextInputValue('ticket-message');
|
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.');
|
||||||
|
|
||||||
const thread = await createPrivateHelpTicketThread(client, guild, member, reason);
|
await interaction.editReply({ content: `Your ticket has been created: ${thread}` });
|
||||||
|
} catch (error: Error | any) {
|
||||||
if (thread) interaction.reply({ flags: [MessageFlags.Ephemeral], content: `Your ticket has been created: ${thread}` });
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
else interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to create ticket. Please report this to a staff member.' });
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new OpenTicketModal();
|
||||||
Reference in New Issue
Block a user