From bb3179f28fe910ea46969613043e4b72df57633e Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 30 Jan 2023 17:10:02 +0000 Subject: [PATCH] minor improvements --- src/commands/slash/force-close.js | 1 + src/lib/logging.js | 5 +---- src/listeners/client/channelDelete.js | 3 ++- src/modals/feedback.js | 14 +++++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/commands/slash/force-close.js b/src/commands/slash/force-close.js index 1876f60..7fca14e 100644 --- a/src/commands/slash/force-close.js +++ b/src/commands/slash/force-close.js @@ -96,6 +96,7 @@ module.exports = class ForceCloseSlashCommand extends SlashCommand { }); } + // TODO: category const tickets = await client.prisma.ticket.findMany({ where: { lastMessageAt: { lte: new Date(Date.now() - time) }, diff --git a/src/lib/logging.js b/src/lib/logging.js index 1b4829c..61463d1 100644 --- a/src/lib/logging.js +++ b/src/lib/logging.js @@ -131,10 +131,7 @@ async function logAdminEvent(client, { async function logTicketEvent(client, { userId, action, target, diff, }) { - const ticket = await client.prisma.ticket.findUnique({ - include: { guild: true }, - where: { id: target.id }, - }); + const ticket = await client.tickets.getTicket(target.id); if (!ticket) return; /** @type {import("discord.js").Guild} */ const guild = client.guilds.cache.get(ticket.guild.id); diff --git a/src/listeners/client/channelDelete.js b/src/listeners/client/channelDelete.js index ff09f4e..b371997 100644 --- a/src/listeners/client/channelDelete.js +++ b/src/listeners/client/channelDelete.js @@ -17,7 +17,8 @@ module.exports = class extends Listener { include: { guild: true }, where: { id: channel.id }, }); - if (!ticket) return; + + if (!ticket?.open) return; await client.tickets.finallyClose(ticket.id, { reason: 'channel deleted' }); this.client.log.info(`Closed ticket ${ticket.id} because the channel was deleted`); diff --git a/src/modals/feedback.js b/src/modals/feedback.js index 05afa42..2c49243 100644 --- a/src/modals/feedback.js +++ b/src/modals/feedback.js @@ -25,14 +25,18 @@ module.exports = class FeedbackModal extends Modal { 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 data = { + comment: comment?.length > 0 ? encrypt(comment) : null, + guild: { connect: { id: interaction.guild.id } }, + rating, + user: { connect: { id: interaction.user.id } }, + }; const ticket = await client.prisma.ticket.update({ data: { feedback: { - create: { - comment: comment?.length > 0 ? encrypt(comment) : null, - guild: { connect: { id: interaction.guild.id } }, - rating, - user: { connect: { id: interaction.user.id } }, + upsert: { + create: data, + update: data, }, }, },