aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/extensions/Util.ts48
-rw-r--r--src/listeners/commands/CommandErrorListener.ts48
2 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts
index 20bfd48..4942bb8 100644
--- a/src/lib/extensions/Util.ts
+++ b/src/lib/extensions/Util.ts
@@ -5,6 +5,8 @@ import { promisify } from 'util';
import { exec } from 'child_process';
import got from 'got';
import { TextChannel } from 'discord.js';
+import { MessageEmbed } from 'discord.js';
+import { GuildMember } from 'discord.js';
interface hastebinRes {
key: string;
@@ -193,4 +195,50 @@ export class Util extends ClientUtil {
)) as TextChannel;
await channel.send(`ERROR: ${message}`);
}
+
+ /**
+ * The colors used throught the bot
+ */
+ public colors = {
+ default: '#1FD8F1',
+ error: '#ff0000',
+ success: '#00ff02',
+ red: '#ff0000',
+ blue: '#0055ff',
+ aqua: '#00bbff',
+ purple: '#8400ff',
+ blurple: '#5440cd',
+ pink: '#ff00e6',
+ green: '#00ff1e',
+ darkgreen: '#008f11',
+ gold: '#b59400',
+ yellow: '#ffff00',
+ white: '#ffffff',
+ gray: '#a6a6a6',
+ lightgray: '#cfcfcf',
+ darkgray: '#7a7a7a',
+ black: '#000000',
+ orange: '#E86100'
+ };
+
+ /**
+ * A simple utility to create and embed with the needed style for the bot
+ */
+ public createEmbed(
+ color?: string,
+ author?: User | GuildMember
+ ): MessageEmbed {
+ if (author instanceof GuildMember) {
+ author = author.user; // Convert to User if GuildMember
+ }
+ let embed = new MessageEmbed().setTimestamp();
+ if (author)
+ embed = embed.setAuthor(
+ author.username,
+ author.displayAvatarURL({ dynamic: true }),
+ `https://discord.com/users/${author.id}`
+ );
+ if (color) embed = embed.setColor(color);
+ return embed;
+ }
}
diff --git a/src/listeners/commands/CommandErrorListener.ts b/src/listeners/commands/CommandErrorListener.ts
new file mode 100644
index 0000000..37179e7
--- /dev/null
+++ b/src/listeners/commands/CommandErrorListener.ts
@@ -0,0 +1,48 @@
+import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BotListener } from '../../lib/extensions/BotListener';
+import { stripIndents } from 'common-tags';
+import { Message } from 'discord.js';
+import { MessageEmbed } from 'discord.js';
+import { TextChannel } from 'discord.js';
+
+export default class CommandErrorListener extends BotListener {
+ constructor() {
+ super('error', {
+ emitter: 'commandHandler',
+ event: 'error'
+ });
+ }
+ async exec(
+ error: Error,
+ message: Message,
+ command?: BotCommand
+ ): Promise<void> {
+ const errorNumber = Math.floor(Math.random() * 6969696969) + 69; // hehe funy numbers
+ const errorDevEmbed = this.client.util
+ .createEmbed(this.client.util.colors.error)
+ .setTitle(`Error # \`${errorNumber}\`: An error occurred`)
+ .setDescription(
+ stripIndents`**User:** ${message.author} (${message.author.tag})
+ **Command:** ${command}
+ **Channel:** ${message.channel} (${message.channel.id})
+ **Message:** [link](${message.url})`
+ )
+ .addField('Error', `${await this.client.util.haste(error.stack)}`);
+ let errorUserEmbed: MessageEmbed;
+ if (command) {
+ errorUserEmbed = this.client.util
+ .createEmbed(this.client.util.colors.error)
+ .setTitle('An error occurred')
+ .setDescription(
+ stripIndents`Whoops! It appears like something broke.
+ The developers have been notified of this. If you contact them, give them code \`${errorNumber}\`.
+ `
+ );
+ }
+ const channel = (await this.client.channels.fetch(
+ this.client.config.channels.log
+ )) as TextChannel;
+ await channel.send(errorDevEmbed);
+ if (errorUserEmbed) await message.reply(errorUserEmbed);
+ }
+}