2022-08-02 20:03:55 +03:00
|
|
|
const { Button } = require('@eartharoid/dbf');
|
2023-01-14 00:25:04 +02:00
|
|
|
const ExtendedEmbedBuilder = require('../lib/embed');
|
2023-01-13 22:48:37 +02:00
|
|
|
const { isStaff } = require('../lib/users');
|
2022-08-02 20:03:55 +03:00
|
|
|
|
|
|
|
module.exports = class CloseButton extends Button {
|
|
|
|
constructor(client, options) {
|
|
|
|
super(client, {
|
|
|
|
...options,
|
|
|
|
id: 'close',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-11 23:24:09 +03:00
|
|
|
/**
|
|
|
|
* @param {*} id
|
|
|
|
* @param {import("discord.js").ButtonInteraction} interaction
|
|
|
|
*/
|
|
|
|
async run(id, interaction) {
|
|
|
|
/** @type {import("client")} */
|
|
|
|
const client = this.client;
|
|
|
|
|
2023-01-13 22:48:37 +02:00
|
|
|
if (id.accepted === undefined) {
|
2023-01-30 17:56:41 +02:00
|
|
|
// the close button on the opening message, the same as using /close
|
2023-01-13 22:48:37 +02:00
|
|
|
await client.tickets.beforeRequestClose(interaction);
|
|
|
|
} else {
|
2023-01-30 17:56:41 +02:00
|
|
|
const ticket = await client.tickets.getTicket(interaction.channel.id);
|
2023-01-14 00:25:04 +02:00
|
|
|
const getMessage = client.i18n.getLocale(ticket.guild.locale);
|
|
|
|
const staff = await isStaff(interaction.guild, interaction.user.id);
|
2023-01-13 22:48:37 +02:00
|
|
|
|
2023-01-14 00:25:04 +02:00
|
|
|
if (id.expect === 'staff' && !staff) {
|
2023-01-30 17:56:41 +02:00
|
|
|
return await interaction.reply({
|
|
|
|
embeds: [
|
|
|
|
new ExtendedEmbedBuilder()
|
|
|
|
.setColor(ticket.guild.errorColour)
|
|
|
|
.setDescription(getMessage('ticket.close.wait_for_staff')),
|
|
|
|
],
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
} else if (id.expect === 'user' && interaction.user.id !== ticket.createdById) {
|
|
|
|
return await interaction.reply({
|
|
|
|
embeds: [
|
|
|
|
new ExtendedEmbedBuilder()
|
|
|
|
.setColor(ticket.guild.errorColour)
|
|
|
|
.setDescription(getMessage('ticket.close.wait_for_user')),
|
|
|
|
],
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
2023-01-14 00:25:04 +02:00
|
|
|
} else {
|
|
|
|
if (id.accepted) {
|
|
|
|
if (
|
|
|
|
ticket.createdById === interaction.user.id &&
|
|
|
|
ticket.category.enableFeedback &&
|
|
|
|
!ticket.feedback
|
|
|
|
) {
|
|
|
|
return await interaction.showModal(client.tickets.buildFeedbackModal(ticket.guild.locale, { next: 'acceptClose' }));
|
|
|
|
} else {
|
2023-01-30 17:56:41 +02:00
|
|
|
await interaction.deferReply();
|
2023-01-14 00:25:04 +02:00
|
|
|
await client.tickets.acceptClose(interaction);
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-10 00:22:47 +02:00
|
|
|
try {
|
|
|
|
await interaction.update({
|
|
|
|
components: [],
|
|
|
|
embeds: [
|
|
|
|
new ExtendedEmbedBuilder({
|
|
|
|
iconURL: interaction.guild.iconURL(),
|
|
|
|
text: ticket.guild.footer,
|
|
|
|
})
|
|
|
|
.setColor(ticket.guild.errorColour)
|
|
|
|
.setDescription(getMessage('ticket.close.rejected', { user: interaction.user.toString() }))
|
|
|
|
.setFooter({ text: null }),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
} finally { // this should run regardless of whatever happens above
|
|
|
|
client.tickets.$stale.delete(ticket.id);
|
2023-01-14 00:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-13 22:48:37 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-11 23:24:09 +03:00
|
|
|
}
|
2022-08-02 20:03:55 +03:00
|
|
|
};
|