diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1ab1954..69c5985 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -188,6 +188,15 @@
"platform",
"doc"
]
+ },
+ {
+ "login": "n1kkl",
+ "name": "Niklas",
+ "avatar_url": "https://avatars.githubusercontent.com/u/100782498?v=4",
+ "profile": "https://github.com/n1kkl",
+ "contributions": [
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index cee0872..194b4be 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -1,7 +1,8 @@
-[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
+[![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors-)
+
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -35,6 +36,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
FoxXxHater 📦 |
AdminRAT 📦 |
c43721 📦 📖 |
+ Niklas 💻 |
diff --git a/src/listeners/channelDelete.js b/src/listeners/channelDelete.js
new file mode 100644
index 0000000..3e4f430
--- /dev/null
+++ b/src/listeners/channelDelete.js
@@ -0,0 +1,23 @@
+const EventListener = require('../modules/listeners/listener');
+
+module.exports = class ChannelDeleteEventListener extends EventListener {
+ constructor(client) {
+ super(client, { event: 'channelDelete' });
+ }
+
+ async execute(channel) {
+ if (!channel.guild || channel.type !== 'GUILD_TEXT') return;
+
+ // resolve ticket by id
+ const t_row = await this.client.tickets.resolve(channel.id, channel.guild.id);
+ if (!t_row) return;
+
+ // fetch user from audit logs
+ const logEntry = (await channel.guild.fetchAuditLogs({ type: 'CHANNEL_DELETE' })).entries.find(entry =>
+ entry.target.id === channel.id
+ );
+ if (logEntry.executor.id === this.client.user.id) return;
+
+ await this.client.tickets.close(t_row.id, logEntry?.executor?.id || null, channel.guild.id, 'Channel was deleted');
+ }
+};
\ No newline at end of file
diff --git a/src/modules/tickets/manager.js b/src/modules/tickets/manager.js
index b19ab10..8a57e84 100644
--- a/src/modules/tickets/manager.js
+++ b/src/modules/tickets/manager.js
@@ -236,15 +236,20 @@ module.exports = class TicketManager extends EventEmitter {
const guild = this.client.guilds.cache.get(t_row.guild);
const settings = await this.client.utils.getSettings(guild.id);
const i18n = this.client.i18n.getLocale(settings.locale);
- const channel = await this.client.channels.fetch(t_row.id);
+ const channel = await this.client.channels.cache.find(channel =>
+ channel.id === t_row.id
+ ) ? await this.client.channels.fetch(t_row.id) : null;
const close = async () => {
- const pinned = await channel.messages.fetchPinned();
+ let pinned;
+ if (channel) {
+ pinned = await channel.messages.fetchPinned();
+ }
await t_row.update({
closed_by: closer_id || null,
closed_reason: reason ? this.client.cryptr.encrypt(reason) : null,
open: false,
- pinned_messages: [...pinned.keys()]
+ pinned_messages: pinned ? [...pinned.keys()] : []
});
if (closer_id) {
@@ -252,42 +257,46 @@ module.exports = class TicketManager extends EventEmitter {
await this.archives.updateMember(ticket_id, closer);
- const description = reason
- ? i18n('ticket.closed_by_member_with_reason.description', closer.user.toString(), reason)
- : i18n('ticket.closed_by_member.description', closer.user.toString());
- await channel.send({
- embeds: [
- new MessageEmbed()
- .setColor(settings.success_colour)
- .setAuthor(closer.user.username, closer.user.displayAvatarURL())
- .setTitle(i18n('ticket.closed.title'))
- .setDescription(description)
- .setFooter(settings.footer, guild.iconURL())
- ]
- });
+ if (channel) {
+ const description = reason
+ ? i18n('ticket.closed_by_member_with_reason.description', closer.user.toString(), reason)
+ : i18n('ticket.closed_by_member.description', closer.user.toString());
+ await channel.send({
+ embeds: [
+ new MessageEmbed()
+ .setColor(settings.success_colour)
+ .setAuthor(closer.user.username, closer.user.displayAvatarURL())
+ .setTitle(i18n('ticket.closed.title'))
+ .setDescription(description)
+ .setFooter(settings.footer, guild.iconURL())
+ ]
+ });
- setTimeout(async () => {
- await channel.delete(`Ticket channel closed by ${closer.user.tag}${reason ? `: "${reason}"` : ''}`);
- }, 5000);
+ setTimeout(async () => {
+ await channel.delete(`Ticket channel closed by ${closer.user.tag}${reason ? `: "${reason}"` : ''}`);
+ }, 5000);
+ }
this.client.log.info(`${closer.user.tag} closed a ticket (${ticket_id})${reason ? `: "${reason}"` : ''}`);
} else {
- const description = reason
- ? i18n('ticket.closed_with_reason.description')
- : i18n('ticket.closed.description');
- await channel.send({
- embeds: [
- new MessageEmbed()
- .setColor(settings.success_colour)
- .setTitle(i18n('ticket.closed.title'))
- .setDescription(description)
- .setFooter(settings.footer, guild.iconURL())
- ]
- });
+ if (channel) {
+ const description = reason
+ ? i18n('ticket.closed_with_reason.description')
+ : i18n('ticket.closed.description');
+ await channel.send({
+ embeds: [
+ new MessageEmbed()
+ .setColor(settings.success_colour)
+ .setTitle(i18n('ticket.closed.title'))
+ .setDescription(description)
+ .setFooter(settings.footer, guild.iconURL())
+ ]
+ });
- setTimeout(async () => {
- await channel.delete(`Ticket channel closed${reason ? `: "${reason}"` : ''}`);
- }, 5000);
+ setTimeout(async () => {
+ await channel.delete(`Ticket channel closed${reason ? `: "${reason}"` : ''}`);
+ }, 5000);
+ }
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
}
@@ -409,6 +418,8 @@ module.exports = class TicketManager extends EventEmitter {
this.client.log.debug(error);
await close();
});
+ } else {
+ await close();
}
this.emit('close', ticket_id);
@@ -423,9 +434,7 @@ module.exports = class TicketManager extends EventEmitter {
async resolve(ticket_id, guild_id) {
let t_row;
- if (this.client.channels.resolve(ticket_id)) {
- t_row = await this.client.db.models.Ticket.findOne({ where: { id: ticket_id } });
- } else {
+ if (!(t_row = await this.client.db.models.Ticket.findOne({ where: { id: ticket_id } }))) {
t_row = await this.client.db.models.Ticket.findOne({
where: {
guild: guild_id,