From 5579362f262c07d879901d31f1a0ec78fa7c7acd Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 30 Jan 2023 16:58:36 +0000 Subject: [PATCH] feat: DM on close (fixes #338) A very basic message to notify the user of the ticket closure --- src/i18n/en-GB.yml | 3 +++ src/lib/tickets/manager.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index 1e478f5..a6aeea8 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -230,6 +230,9 @@ commands: create: name: Create a ticket for user dm: + closed: + archived: Type `/transcript` in **{guild}** to view the archived messages. + title: Your ticket has been closed confirm_open: title: Do you want to open a ticket with the following topic? log: diff --git a/src/lib/tickets/manager.js b/src/lib/tickets/manager.js index 44e97f4..0c58817 100644 --- a/src/lib/tickets/manager.js +++ b/src/lib/tickets/manager.js @@ -1081,10 +1081,38 @@ module.exports = class TicketManager { where: { id: ticket.id }, }); - if (channel?.deletable) { const member = closedBy ? channel.guild.members.cache.get(closedBy) : null; await channel.delete('Ticket closed' + (member ? ` by ${member.displayName}` : '') + reason ? `: ${reason}` : ''); } + + if (closedBy) { + logTicketEvent(this.client, { + action: 'close', + target: { + id: ticket.id, + name: channel.toString(), + }, + userId: closedBy, + }); + } + + try { + const creator = await channel?.guild.members.fetch(ticket.createdById); + if (creator) { + const getMessage = this.client.i18n.getLocale(ticket.guild.locale); + const embed = new ExtendedEmbedBuilder({ + iconURL: channel.guild.iconURL(), + text: ticket.guild.footer, + }) + .setColor(ticket.guild.primaryColour) + .setTitle(getMessage('dm.closed.title')); + if (ticket.guild.archive) embed.setDescription(getMessage('dm.closed.archived', { guild: channel.guild.name })); + await creator.send({ embeds: [embed] }); + } + } catch (error) { + this.client.log.error(error); + } + } }; \ No newline at end of file