fix: ticket closing

This commit is contained in:
Isaac
2023-01-30 15:56:41 +00:00
parent a60c998605
commit d1c3620fcd
15 changed files with 213 additions and 100 deletions

View File

@@ -1,5 +1,8 @@
const { Modal } = require('@eartharoid/dbf');
const ExtendedEmbedBuilder = require('../lib/embed');
const Cryptr = require('cryptr');
const { encrypt } = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class FeedbackModal extends Modal {
constructor(client, options) {
super(client, {
@@ -19,13 +22,14 @@ module.exports = class FeedbackModal extends Modal {
await interaction.deferReply();
const comment = interaction.fields.getTextInputValue('comment');
const rating = parseInt(interaction.fields.getTextInputValue('rating')) || null;
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)
const ticket = await client.prisma.ticket.update({
data: {
feedback: {
create: {
comment,
comment: comment?.length > 0 ? encrypt(comment) : null,
guild: { connect: { id: interaction.guild.id } },
rating,
user: { connect: { id: interaction.user.id } },
@@ -36,6 +40,7 @@ module.exports = class FeedbackModal extends Modal {
where: { id: interaction.channel.id },
});
if (id.next === 'requestClose') await client.tickets.requestClose(interaction, id.reason);
else if (id.next === 'acceptClose') await client.tickets.acceptClose(interaction);