From efe7ede041086696204631653667edee05781c89 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 6 Aug 2022 21:58:02 +0100 Subject: [PATCH] Make sure category hasn't been deleted --- src/i18n/en-GB.yml | 5 ++++- src/lib/tickets/manager.js | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index 5eb9901..f8eb71d 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -162,4 +162,7 @@ modals: misc: no_categories: description: No ticket categories have been configured. - title: ❌ There are no ticket categories \ No newline at end of file + title: ❌ There are no ticket categories + unknown_category: + description: Please try a different category. + title: ❌ That ticket category doesn't exist \ No newline at end of file diff --git a/src/lib/tickets/manager.js b/src/lib/tickets/manager.js index 7fb450e..4431fd0 100644 --- a/src/lib/tickets/manager.js +++ b/src/lib/tickets/manager.js @@ -8,6 +8,7 @@ const { } = require('discord.js'); const emoji = require('node-emoji'); const ms = require('ms'); +const { EmbedBuilder } = require('discord.js'); module.exports = class TicketManager { constructor(client) { @@ -35,10 +36,30 @@ module.exports = class TicketManager { }, where: { id: Number(categoryId) }, }); + if (!category) { + let settings; + if (interaction.guild) { + settings = await this.client.prisma.guild.findUnique({ where: { id: interaction.guild.id } }); + } else { + settings = { + errorColour: 'Red', + locale: 'en-GB', + }; + } + const getMessage = this.client.i18n.getLocale(settings.locale); + return await interaction.reply({ + embeds: [ + new EmbedBuilder() + .setColor(settings.errorColour) + .setTitle(getMessage('misc.unknown_category.title')) + .setDescription(getMessage('misc.unknown_category.description')) + .setFooter(settings.footer), + ], + }); + } this.client.keyv.set(cacheKey, category, ms('5m')); } - // TODO: if member !required roles -> stop // TODO: if discordCategory has 50 channels -> stop @@ -51,7 +72,8 @@ module.exports = class TicketManager { // TODO: if 10s ratelimit -> stop - const getMessage = this.client.i18n.getLocale(category.guild.locale); + + const getMessage = this.client.i18n.getLocale(category.guild.locale); if (category.questions.length >= 1) { await interaction.showModal(