From d1e30ce069c4999a82b2381df39fc3d613cd06de Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 25 Aug 2023 01:22:11 +0100 Subject: [PATCH] fix: update counters when transferring (closes #468) --- src/commands/slash/transfer.js | 59 +++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/commands/slash/transfer.js b/src/commands/slash/transfer.js index dae895f..857dbe9 100644 --- a/src/commands/slash/transfer.js +++ b/src/commands/slash/transfer.js @@ -49,29 +49,46 @@ module.exports = class TransferSlashCommand extends SlashCommand { }, where: { id: interaction.channel.id }, }); - const from = ticket.createdById; - await client.prisma.ticket.update({ - data: { - createdBy: { - connectOrCreate: { - create: { id: member.id }, - where: { id: member.id }, - }, - }, - }, - where: { id: interaction.channel.id }, - }); + const from = ticket.createdById; const channelName = ticket.category.channelName .replace(/{+\s?(user)?name\s?}+/gi, member.user.username) .replace(/{+\s?(nick|display)(name)?\s?}+/gi, member.displayName) .replace(/{+\s?num(ber)?\s?}+/gi, ticket.number === 1488 ? '1487b' : ticket.number); - await interaction.channel.edit({ - name: channelName, - topic: `${member.toString()}${ticket.topic?.length > 0 ? ` | ${decrypt(ticket.topic)}` : ''}`, - }); + await Promise.all([ + client.prisma.ticket.update({ + data: { + createdBy: { + connectOrCreate: { + create: { id: member.id }, + where: { id: member.id }, + }, + }, + }, + where: { id: interaction.channel.id }, + }), + interaction.channel.edit({ + name: channelName, + topic: `${member.toString()}${ticket.topic?.length > 0 ? ` | ${decrypt(ticket.topic)}` : ''}`, + }), + interaction.channel.permissionOverwrites.edit( + member, + { + AttachFiles: true, + EmbedLinks: true, + ReadMessageHistory: true, + SendMessages: true, + ViewChannel: true, + }, + ), + ]); + + const $category = client.tickets.$count.categories[ticket.categoryId]; + $category[from]--; + $category[member.id] ||= 0; + $category[member.id]++; await interaction.editReply({ embeds: [ @@ -86,15 +103,5 @@ module.exports = class TransferSlashCommand extends SlashCommand { ], }); - await interaction.channel.permissionOverwrites.edit( - member, - { - AttachFiles: true, - EmbedLinks: true, - ReadMessageHistory: true, - SendMessages: true, - ViewChannel: true, - }, - ); } };