feat: make closed ticket DM more useful

This commit is contained in:
Isaac 2023-02-09 21:51:28 +00:00
parent 5982754813
commit a0ffbae36d
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 92 additions and 7 deletions

View File

@ -231,7 +231,18 @@ commands:
name: Create a ticket for user name: Create a ticket for user
dm: dm:
closed: closed:
archived: Type `/transcript` in **{guild}** to view the archived messages. archived: Use the `/transcript` command in **{guild}** to view the archived messages.
fields:
closed:
name: Closed at
value: "{timestamp} (after {duration})"
closed_by: Closed by
created: Created at
feedback: Your feedback
reason: Closed because
response: Response time
ticket: Ticket
topic: Topic
title: Your ticket has been closed title: Your ticket has been closed
confirm_open: confirm_open:
title: Do you want to open a ticket with the following topic? title: Do you want to open a ticket with the following topic?

View File

@ -19,7 +19,10 @@ const { logTicketEvent } = require('../logging');
const { isStaff } = require('../users'); const { isStaff } = require('../users');
const { Collection } = require('discord.js'); const { Collection } = require('discord.js');
const Cryptr = require('cryptr'); const Cryptr = require('cryptr');
const { encrypt } = new Cryptr(process.env.ENCRYPTION_KEY); const {
decrypt,
encrypt,
} = new Cryptr(process.env.ENCRYPTION_KEY);
/** /**
* @typedef {import('@prisma/client').Category & * @typedef {import('@prisma/client').Category &
@ -1047,7 +1050,8 @@ module.exports = class TicketManager {
closedBy = null, closedBy = null,
reason = null, reason = null,
}) { }) {
const ticket = await this.getTicket(ticketId); let ticket = await this.getTicket(ticketId);
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);
this.$count.categories[ticket.categoryId].total -= 1; this.$count.categories[ticket.categoryId].total -= 1;
this.$count.categories[ticket.categoryId][ticket.createdById] -= 1; this.$count.categories[ticket.categoryId][ticket.createdById] -= 1;
@ -1077,8 +1081,13 @@ module.exports = class TicketManager {
data.pinnedMessageIds = [...pinned.keys()]; data.pinnedMessageIds = [...pinned.keys()];
} }
await this.client.prisma.ticket.update({ ticket = await this.client.prisma.ticket.update({
data, data,
include: {
category: true,
feedback: true,
guild: true,
},
where: { id: ticket.id }, where: { id: ticket.id },
}); });
@ -1092,7 +1101,7 @@ module.exports = class TicketManager {
action: 'close', action: 'close',
target: { target: {
id: ticket.id, id: ticket.id,
name: `[${ticket.number}]`, name: `${ticket.category.name} **#${ticket.number}**`,
}, },
userId: closedBy, userId: closedBy,
}); });
@ -1101,14 +1110,79 @@ module.exports = class TicketManager {
try { try {
const creator = await channel?.guild.members.fetch(ticket.createdById); const creator = await channel?.guild.members.fetch(ticket.createdById);
if (creator) { if (creator) {
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);
const embed = new ExtendedEmbedBuilder({ const embed = new ExtendedEmbedBuilder({
iconURL: channel.guild.iconURL(), iconURL: channel.guild.iconURL(),
text: ticket.guild.footer, text: ticket.guild.footer,
}) })
.setColor(ticket.guild.primaryColour) .setColor(ticket.guild.primaryColour)
.setTitle(getMessage('dm.closed.title')); .setTitle(getMessage('dm.closed.title'))
.addFields([
{
inline: true,
name: getMessage('dm.closed.fields.ticket'),
value: `${ticket.category.name} **#${ticket.number}**`,
},
]);
if (ticket.topic) {
embed.addFields({
inline: true,
name: getMessage('dm.closed.fields.topic'),
value: decrypt(ticket.topic),
});
}
embed.addFields([
{
inline: true,
name: getMessage('dm.closed.fields.created'),
value: `<t:${Math.floor(ticket.createdAt / 1000)}:f>`,
},
{
inline: true,
name: getMessage('dm.closed.fields.closed.name'),
value: getMessage('dm.closed.fields.closed.value', {
duration: ms(ticket.closedAt - ticket.createdAt, { long: true }),
timestamp: `<t:${Math.floor(ticket.closedAt / 1000)}:f>`,
}),
},
]);
if (ticket.firstResponseAt) {
embed.addFields({
inline: true,
name: getMessage('dm.closed.fields.response'),
value: ms(ticket.firstResponseAt - ticket.createdAt, { long: true }),
});
}
if (ticket.feedback) {
embed.addFields({
inline: true,
name: getMessage('dm.closed.fields.feedback'),
value: Array(ticket.feedback.rating).fill('⭐').join(' ') + ` (${ticket.feedback.rating}/5)`,
});
}
if (ticket.closedById) {
embed.addFields({
inline: true,
name: getMessage('dm.closed.fields.closed_by'),
value: `<@${ticket.closedById}>`,
});
}
if (reason) {
embed.addFields({
inline: true,
name: getMessage('dm.closed.fields.reason'),
value: reason,
});
}
if (ticket.guild.archive) embed.setDescription(getMessage('dm.closed.archived', { guild: channel.guild.name })); if (ticket.guild.archive) embed.setDescription(getMessage('dm.closed.archived', { guild: channel.guild.name }));
await creator.send({ embeds: [embed] }); await creator.send({ embeds: [embed] });
} }
} catch (error) { } catch (error) {