mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-04 09:21:25 +03:00
more on closing and feedback (WIP)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { Button } = require('@eartharoid/dbf');
|
||||
const ExtendedEmbedBuilder = require('../lib/embed');
|
||||
const { isStaff } = require('../lib/users');
|
||||
|
||||
module.exports = class CloseButton extends Button {
|
||||
@@ -17,28 +18,55 @@ module.exports = class CloseButton extends Button {
|
||||
/** @type {import("client")} */
|
||||
const client = this.client;
|
||||
|
||||
// the close button on th opening message, the same as using /close
|
||||
if (id.accepted === undefined) {
|
||||
await client.tickets.beforeRequestClose(interaction);
|
||||
} else {
|
||||
// {
|
||||
// action: 'close',
|
||||
// expect: staff ? 'user' : 'staff',
|
||||
// reason: interaction.options?.getString('reason', false) || null, // ?. because it could be a button interaction
|
||||
// requestedBy: interaction.user.id,
|
||||
// }
|
||||
|
||||
await interaction.deferReply();
|
||||
const ticket = await client.prisma.ticket.findUnique({
|
||||
include: { guild: true },
|
||||
include: {
|
||||
category: true,
|
||||
guild: true,
|
||||
},
|
||||
where: { id: interaction.channel.id },
|
||||
});
|
||||
const getMessage = client.i18n.getLocale(ticket.guild.locale);
|
||||
const staff = await isStaff(interaction.guild, interaction.user.id);
|
||||
|
||||
if (id.expect === 'staff' && !await isStaff(interaction.guild, interaction.user.id)) {
|
||||
return;
|
||||
} else if (interaction.user.id !== ticket.createdById) {
|
||||
return;
|
||||
// if user and expect user (or is creator), feedback modal (if enabled)
|
||||
// otherwise add "Give feedback" button in DM message (if enabled)
|
||||
if (id.expect === 'staff' && !staff) {
|
||||
return; // TODO: please wait for staff to close the ticket
|
||||
} else if (id.expect === 'user' && staff) {
|
||||
return; // TODO: please wait for the user to respond
|
||||
} 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 {
|
||||
await client.tickets.acceptClose(interaction);
|
||||
}
|
||||
} else {
|
||||
if (client.tickets.$stale.has(ticket.id)) {
|
||||
await interaction.channel.messages.edit(
|
||||
client.tickets.$stale.get(ticket.id).message.id,
|
||||
{
|
||||
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() })),
|
||||
],
|
||||
},
|
||||
);
|
||||
client.tickets.$stale.delete(ticket.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user