From c9609a41b52053ff181c3dd4d793d9db97a265c4 Mon Sep 17 00:00:00 2001 From: Isaac Date: Tue, 11 May 2021 11:52:23 +0100 Subject: [PATCH] Ticket creation error handling --- src/commands/blacklist.js | 2 -- src/commands/close.js | 2 -- src/commands/new.js | 31 ++++++++++++++++++++----------- src/commands/panel.js | 3 +-- src/commands/settings.js | 3 +-- src/commands/transfer.js | 2 -- src/locales/en-GB.json | 2 +- src/modules/tickets/manager.js | 5 +++++ 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/commands/blacklist.js b/src/commands/blacklist.js index 26fab2d..82b5d4e 100644 --- a/src/commands/blacklist.js +++ b/src/commands/blacklist.js @@ -25,7 +25,6 @@ module.exports = class BlacklistCommand extends Command { } async execute(message, args) { - let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); @@ -101,6 +100,5 @@ module.exports = class BlacklistCommand extends Command { settings.blacklist = new_blacklist; await settings.save(); - } }; \ No newline at end of file diff --git a/src/commands/close.js b/src/commands/close.js index 3b697fb..e21f252 100644 --- a/src/commands/close.js +++ b/src/commands/close.js @@ -25,9 +25,7 @@ module.exports = class CloseCommand extends Command { } async execute(message, args) { - let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); - } }; \ No newline at end of file diff --git a/src/commands/new.js b/src/commands/new.js index bff28c5..2f761c8 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -28,7 +28,6 @@ module.exports = class NewCommand extends Command { } async execute(message, args) { - let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); @@ -76,15 +75,26 @@ module.exports = class NewCommand extends Command { ); } } else { - let t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args); - response = await editOrSend(response, - new MessageEmbed() - .setColor(settings.success_colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(i18n('commands.new.response.created.title')) - .setDescription(i18n('commands.new.response.created.description', `<#${t_row.id}>`)) - .setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL()) - ); + try { + let t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args); + response = await editOrSend(response, + new MessageEmbed() + .setColor(settings.success_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(i18n('commands.new.response.created.title')) + .setDescription(i18n('commands.new.response.created.description', `<#${t_row.id}>`)) + .setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL()) + ); + } catch (error) { + response = await editOrSend(response, + new MessageEmbed() + .setColor(settings.error_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(i18n('commands.new.response.error.title')) + .setDescription(error.message) + .setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL()) + ); + } } setTimeout(async () => { @@ -169,6 +179,5 @@ module.exports = class NewCommand extends Command { } }); } - } }; diff --git a/src/commands/panel.js b/src/commands/panel.js index 962d60c..0684840 100644 --- a/src/commands/panel.js +++ b/src/commands/panel.js @@ -55,7 +55,6 @@ module.exports = class PanelCommand extends Command { } async execute(message, args) { - const arg_title = this.args[0].name; const arg_description = this.args[1].name; const arg_emoji = this.args[2].name; @@ -66,6 +65,7 @@ module.exports = class PanelCommand extends Command { console.log(args) message.channel.send(Object.keys(args).map(arg => `${arg}: \`${args[arg]}\``).join('\n')) + console.log(args.category) if (!args[arg_emoji]) { // reaction-less panel @@ -80,6 +80,5 @@ module.exports = class PanelCommand extends Command { } } } - } }; \ No newline at end of file diff --git a/src/commands/settings.js b/src/commands/settings.js index 6806926..2324235 100644 --- a/src/commands/settings.js +++ b/src/commands/settings.js @@ -17,7 +17,6 @@ module.exports = class SettingsCommand extends Command { } async execute(message) { - let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); @@ -191,7 +190,7 @@ module.exports = class SettingsCommand extends Command { message.channel.send({ files: [attachment] }); - + } } }; \ No newline at end of file diff --git a/src/commands/transfer.js b/src/commands/transfer.js index 09cdd96..dd5c85b 100644 --- a/src/commands/transfer.js +++ b/src/commands/transfer.js @@ -23,9 +23,7 @@ module.exports = class TransferCommand extends Command { } async execute(message, args) { - let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); - } }; \ No newline at end of file diff --git a/src/locales/en-GB.json b/src/locales/en-GB.json index a646296..e91cca5 100644 --- a/src/locales/en-GB.json +++ b/src/locales/en-GB.json @@ -169,7 +169,7 @@ "emoji": { "alias": "e", "description": "A **unicode** emoji character (escaped emoji)", - "example": "\\:ticket:", + "example": "🎫", "name": "emoji" }, "title": { diff --git a/src/modules/tickets/manager.js b/src/modules/tickets/manager.js index bf55d71..e86c4f8 100644 --- a/src/modules/tickets/manager.js +++ b/src/modules/tickets/manager.js @@ -156,6 +156,11 @@ module.exports = class TicketManager extends EventEmitter { if (!cat_row) throw new Error('Ticket category does not exist'); + + let cat_channel = await this.client.channels.fetch(category_id); + + if (cat_channel.children.size >= 50) + throw new Error('Ticket category has reached child channel limit (50)'); let number = (await this.client.db.models.Ticket.count({ where: {