2022-08-02 20:03:55 +03:00
|
|
|
const { Modal } = require('@eartharoid/dbf');
|
2023-01-14 00:25:04 +02:00
|
|
|
const ExtendedEmbedBuilder = require('../lib/embed');
|
2023-01-30 17:56:41 +02:00
|
|
|
const Cryptr = require('cryptr');
|
|
|
|
const { encrypt } = new Cryptr(process.env.ENCRYPTION_KEY);
|
|
|
|
|
2022-08-02 20:03:55 +03:00
|
|
|
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
|
|
|
|
*/
|
2023-01-13 22:48:37 +02:00
|
|
|
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');
|
2023-01-30 17:56:41 +02:00
|
|
|
let rating = parseInt(interaction.fields.getTextInputValue('rating')) || null; // any integer, or null if NaN
|
|
|
|
rating = Math.min(Math.max(rating, 1), 5); // clamp between 1 and 5 (0 and null become 1, 6 becomes 5)
|
2023-01-14 00:25:04 +02:00
|
|
|
|
2023-01-30 19:10:02 +02:00
|
|
|
const data = {
|
|
|
|
comment: comment?.length > 0 ? encrypt(comment) : null,
|
|
|
|
guild: { connect: { id: interaction.guild.id } },
|
|
|
|
rating,
|
|
|
|
user: { connect: { id: interaction.user.id } },
|
|
|
|
};
|
2023-01-14 00:25:04 +02:00
|
|
|
const ticket = await client.prisma.ticket.update({
|
2023-01-13 22:48:37 +02:00
|
|
|
data: {
|
|
|
|
feedback: {
|
2023-01-30 19:10:02 +02:00
|
|
|
upsert: {
|
|
|
|
create: data,
|
|
|
|
update: data,
|
2023-01-13 22:48:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-14 00:25:04 +02:00
|
|
|
include: { guild: true },
|
2023-01-13 22:48:37 +02:00
|
|
|
where: { id: interaction.channel.id },
|
|
|
|
});
|
2023-01-14 00:25:04 +02:00
|
|
|
|
2023-01-30 17:56:41 +02:00
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2023-01-13 22:48:37 +02:00
|
|
|
}
|
2022-08-02 20:03:55 +03:00
|
|
|
};
|