feat: close tickets on channel delete

This commit is contained in:
Isaac 2023-01-02 13:27:02 +00:00
parent 8e82b2829f
commit 813beb44a0
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -0,0 +1,25 @@
const { Listener } = require('@eartharoid/dbf');
module.exports = class extends Listener {
constructor(client, options) {
super(client, {
...options,
emitter: client,
event: 'channelDelete',
});
}
async run(channel) {
/** @type {import("client")} */
const client = this.client;
const ticket = await client.prisma.ticket.findUnique({
include: { guild: true },
where: { id: channel.id },
});
if (!ticket) return;
await client.tickets.close(ticket.id, true, 'channel deleted');
this.client.log.info(`Closed ticket ${ticket.id} because the channel was deleted`);
}
};