Ticket creation error handling

This commit is contained in:
Isaac 2021-05-11 11:52:23 +01:00
parent 10f449fc2d
commit c9609a41b5
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
8 changed files with 28 additions and 22 deletions

View File

@ -25,7 +25,6 @@ module.exports = class BlacklistCommand extends Command {
} }
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
@ -101,6 +100,5 @@ module.exports = class BlacklistCommand extends Command {
settings.blacklist = new_blacklist; settings.blacklist = new_blacklist;
await settings.save(); await settings.save();
} }
}; };

View File

@ -25,9 +25,7 @@ module.exports = class CloseCommand extends Command {
} }
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
} }
}; };

View File

@ -28,7 +28,6 @@ module.exports = class NewCommand extends Command {
} }
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
@ -76,15 +75,26 @@ module.exports = class NewCommand extends Command {
); );
} }
} else { } else {
let t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args); try {
response = await editOrSend(response, let t_row = await this.client.tickets.create(message.guild.id, message.author.id, cat_row.id, args);
new MessageEmbed() response = await editOrSend(response,
.setColor(settings.success_colour) new MessageEmbed()
.setAuthor(message.author.username, message.author.displayAvatarURL()) .setColor(settings.success_colour)
.setTitle(i18n('commands.new.response.created.title')) .setAuthor(message.author.username, message.author.displayAvatarURL())
.setDescription(i18n('commands.new.response.created.description', `<#${t_row.id}>`)) .setTitle(i18n('commands.new.response.created.title'))
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL()) .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 () => { setTimeout(async () => {
@ -169,6 +179,5 @@ module.exports = class NewCommand extends Command {
} }
}); });
} }
} }
}; };

View File

@ -55,7 +55,6 @@ module.exports = class PanelCommand extends Command {
} }
async execute(message, args) { async execute(message, args) {
const arg_title = this.args[0].name; const arg_title = this.args[0].name;
const arg_description = this.args[1].name; const arg_description = this.args[1].name;
const arg_emoji = this.args[2].name; const arg_emoji = this.args[2].name;
@ -66,6 +65,7 @@ module.exports = class PanelCommand extends Command {
console.log(args) console.log(args)
message.channel.send(Object.keys(args).map(arg => `${arg}: \`${args[arg]}\``).join('\n')) message.channel.send(Object.keys(args).map(arg => `${arg}: \`${args[arg]}\``).join('\n'))
console.log(args.category)
if (!args[arg_emoji]) { if (!args[arg_emoji]) {
// reaction-less panel // reaction-less panel
@ -80,6 +80,5 @@ module.exports = class PanelCommand extends Command {
} }
} }
} }
} }
}; };

View File

@ -17,7 +17,6 @@ module.exports = class SettingsCommand extends Command {
} }
async execute(message) { async execute(message) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
@ -191,7 +190,7 @@ module.exports = class SettingsCommand extends Command {
message.channel.send({ message.channel.send({
files: [attachment] files: [attachment]
}); });
} }
} }
}; };

View File

@ -23,9 +23,7 @@ module.exports = class TransferCommand extends Command {
} }
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
} }
}; };

View File

@ -169,7 +169,7 @@
"emoji": { "emoji": {
"alias": "e", "alias": "e",
"description": "A **unicode** emoji character (escaped emoji)", "description": "A **unicode** emoji character (escaped emoji)",
"example": "\\:ticket:", "example": "🎫",
"name": "emoji" "name": "emoji"
}, },
"title": { "title": {

View File

@ -156,6 +156,11 @@ module.exports = class TicketManager extends EventEmitter {
if (!cat_row) if (!cat_row)
throw new Error('Ticket category does not exist'); 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({ let number = (await this.client.db.models.Ticket.count({
where: { where: {