Make sure category hasn't been deleted

This commit is contained in:
Isaac 2022-08-06 21:58:02 +01:00
parent 0a10d91f8d
commit efe7ede041
No known key found for this signature in database
GPG Key ID: F4EAABEB0FFCC06A
2 changed files with 28 additions and 3 deletions

View File

@ -163,3 +163,6 @@ misc:
no_categories:
description: No ticket categories have been configured.
title: ❌ There are no ticket categories
unknown_category:
description: Please try a different category.
title: ❌ That ticket category doesn't exist

View File

@ -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(