feat: add /topic command

This commit is contained in:
Isaac 2022-10-25 22:56:13 +01:00
parent 30883032b7
commit f27feea2f9
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -1,5 +1,12 @@
const { SlashCommand } = require('@eartharoid/dbf'); 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 { module.exports = class TopicSlashCommand extends SlashCommand {
constructor(client, options) { 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) : ''),
),
),
);
}
}; };