Respond with error messages

instead of giving the user no information.
This commit is contained in:
Isaac 2022-10-31 15:35:41 +00:00
parent 76ed77fe0c
commit b61b3dd2b1
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
3 changed files with 103 additions and 9 deletions

View File

@ -68,9 +68,6 @@ commands:
reason:
description: The reason for closing the ticket(s)
name: reason
ticket:
description: The ticket to close
name: ticket
force-close:
confirm_multiple:
description: >
@ -120,7 +117,7 @@ commands:
settings: Bot settings
title: Help
move:
description: move a ticket to another category
description: Move a ticket to another category
name: move
options:
category:
@ -220,7 +217,8 @@ commands:
member:
description: The member to transfer ownership to
name: member
transferred: 📨 {user} has transferred this ticket from {from} to {to}.
transferred: 📨 {user} has transferred this ticket to {to}.
transferred_from: 📨 {user} has transferred this ticket from {from} to {to}.
user:
create:
name: Create a ticket for user
@ -289,8 +287,9 @@ misc:
error:
description: Sorry, an unexpected error occurred.
fields:
code: Error code
identifier: Identifier
title: ⚠️ Something's wrong
title: ⚠️ Something went wrong
expired:
description: You didn't respond in time. Please try again.
title: ⏰ Expired
@ -334,7 +333,6 @@ ticket:
answers:
no_value: "*No response*"
claimed: 🙌 {user} has claimed this ticket.
released: ♻️ {user} has released this ticket.
created:
description: "Your ticket channel has been created: {channel}."
title: ✅ Ticket created
@ -357,3 +355,4 @@ ticket:
number: Number
topic: Topic
title: Reference
released: ♻️ {user} has released this ticket.

View File

@ -0,0 +1,57 @@
const { Listener } = require('@eartharoid/dbf');
const {
EmbedBuilder,
inlineCode,
} = require('discord.js');
module.exports = class extends Listener {
constructor(client, options) {
super(client, {
...options,
emitter: client.buttons,
event: 'error',
});
}
async run({
button,
error,
interaction,
}) {
const ref = require('crypto').randomUUID();
this.client.log.error.buttons(ref);
this.client.log.error.buttons(`"${button.name}" button execution error:`, error);
let locale = null;
if (interaction.guild) {
locale = (await this.client.prisma.guild.findUnique({
select: { locale: true },
where: { id: interaction.guild.id },
})).locale;
}
const getMessage = this.client.i18n.getLocale(locale);
const fields = [
{
name: getMessage('misc.error.fields.identifier'),
value: inlineCode(ref),
},
];
if (error.name) {
fields.unshift({
name: getMessage('misc.error.fields.code'),
value: inlineCode(error.name),
});
}
const data = {
components: [],
embeds: [
new EmbedBuilder()
.setColor('Orange')
.setTitle(getMessage('misc.error.title'))
.setDescription(getMessage('misc.error.description'))
.addFields(fields),
],
};
interaction.reply(data).catch(() => interaction.editReply(data));
}
};

View File

@ -1,4 +1,8 @@
const { Listener } = require('@eartharoid/dbf');
const {
EmbedBuilder,
inlineCode,
} = require('discord.js');
module.exports = class extends Listener {
constructor(client, options) {
@ -9,11 +13,45 @@ module.exports = class extends Listener {
});
}
run({
async run({
command,
error,
interaction,
}) {
const ref = require('crypto').randomUUID();
this.client.log.error.commands(ref);
this.client.log.error.commands(`"${command.name}" command execution error:`, error);
return true;
let locale = null;
if (interaction.guild) {
locale = (await this.client.prisma.guild.findUnique({
select: { locale: true },
where: { id: interaction.guild.id },
})).locale;
}
const getMessage = this.client.i18n.getLocale(locale);
const fields = [
{
name: getMessage('misc.error.fields.identifier'),
value: inlineCode(ref),
},
];
if (error.name) {
fields.unshift({
name: getMessage('misc.error.fields.code'),
value: inlineCode(error.name),
});
}
const data = {
components: [],
embeds: [
new EmbedBuilder()
.setColor('Orange')
.setTitle(getMessage('misc.error.title'))
.setDescription(getMessage('misc.error.description'))
.addFields(fields),
],
};
interaction.reply(data).catch(() => interaction.editReply(data));
}
};