DiscordTickets/src/modals/feedback.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

const { Modal } = require('@eartharoid/dbf');
2023-01-14 00:25:04 +02:00
const ExtendedEmbedBuilder = require('../lib/embed');
module.exports = class FeedbackModal extends Modal {
constructor(client, options) {
super(client, {
...options,
id: 'feedback',
});
}
2023-01-14 00:25:04 +02:00
/**
* @param {*} id
* @param {import("discord.js").ModalSubmitInteraction} interaction
*/
async run(id, interaction) {
/** @type {import("client")} */
const client = this.client;
await interaction.deferReply();
2023-01-14 00:25:04 +02:00
const comment = interaction.fields.getTextInputValue('comment');
const rating = parseInt(interaction.fields.getTextInputValue('rating')) || null;
const ticket = await client.prisma.ticket.update({
data: {
feedback: {
create: {
2023-01-14 00:25:04 +02:00
comment,
guild: { connect: { id: interaction.guild.id } },
2023-01-14 00:25:04 +02:00
rating,
user: { connect: { id: interaction.user.id } },
},
},
},
2023-01-14 00:25:04 +02:00
include: { guild: true },
where: { id: interaction.channel.id },
});
2023-01-14 00:25:04 +02:00
if (id.next === 'requestClose') await client.tickets.requestClose(interaction, id.reason);
else if (id.next === 'acceptClose') await client.tickets.acceptClose(interaction);
const getMessage = client.i18n.getLocale(ticket.guild.locale);
// `followUp` must go after `reply`/`editReply` (the above)
if (comment?.length > 0 && rating !== null) {
await interaction.followUp({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.primaryColour)
.setDescription(getMessage('ticket.feedback')),
],
ephemeral: true,
});
}
}
};