From 813beb44a0456a0870671fccecb458d6a1cd7560 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 2 Jan 2023 13:27:02 +0000 Subject: [PATCH] feat: close tickets on channel delete --- src/listeners/client/channelDelete.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/listeners/client/channelDelete.js diff --git a/src/listeners/client/channelDelete.js b/src/listeners/client/channelDelete.js new file mode 100644 index 0000000..58e5dc3 --- /dev/null +++ b/src/listeners/client/channelDelete.js @@ -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`); + } +};