diff --git a/src/commands/slash/topic.js b/src/commands/slash/topic.js index 8fe6b39..c3e8049 100644 --- a/src/commands/slash/topic.js +++ b/src/commands/slash/topic.js @@ -1,5 +1,12 @@ const { SlashCommand } = require('@eartharoid/dbf'); -const { ApplicationCommandOptionType } = require('discord.js'); +const { + ActionRowBuilder, + ModalBuilder, + TextInputBuilder, + TextInputStyle, +} = require('discord.js'); +const Cryptr = require('cryptr'); +const { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY); module.exports = class TopicSlashCommand extends SlashCommand { constructor(client, options) { @@ -19,5 +26,46 @@ module.exports = class TopicSlashCommand extends SlashCommand { }); } - async run(interaction) { } + /** + * @param {import("discord.js").ChatInputCommandInteraction} interaction + */ + async run(interaction) { + /** @type {import("client")} */ + const client = this.client; + + const ticket = await client.prisma.ticket.findUnique({ + select: { + category: { select: { name: true } }, + guild: { select: { locale: true } }, + questionAnswers: { include: { question: true } }, + topic: true, + }, + where: { id: interaction.channel.id }, + }); + + const getMessage = client.i18n.getLocale(ticket.guild.locale); + + await interaction.showModal( + new ModalBuilder() + .setCustomId(JSON.stringify({ + action: 'topic', + edit: true, + })) + .setTitle(ticket.category.name) + .setComponents( + new ActionRowBuilder() + .setComponents( + new TextInputBuilder() + .setCustomId('topic') + .setLabel(getMessage('modals.topic.label')) + .setStyle(TextInputStyle.Paragraph) + .setMaxLength(1000) + .setMinLength(5) + .setPlaceholder(getMessage('modals.topic.placeholder')) + .setRequired(true) + .setValue(ticket.topic ? decrypt(ticket.topic) : ''), + ), + ), + ); + } }; \ No newline at end of file