2022-08-02 20:03:55 +03:00
|
|
|
const { Button } = require('@eartharoid/dbf');
|
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) {
|
|
|
|
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 },
|
|
|
|
where: { id: interaction.channel.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)
|
|
|
|
}
|
|
|
|
}
|
2022-10-11 23:24:09 +03:00
|
|
|
}
|
2022-08-02 20:03:55 +03:00
|
|
|
};
|