error handling funcs
parent
d922b15475
commit
bc72e484f8
|
@ -27,6 +27,7 @@ export default class Client extends eris.Client {
|
|||
// eslint-disable-next-line
|
||||
const event = new (require(`${__dirname}/../events/${file}`).default)(this);
|
||||
this.on(eventName, (...args) => event.run(...args));
|
||||
this.util.signale.success(`Successfully loaded event: ${eventName}`);
|
||||
delete require.cache[require.resolve(`${__dirname}/../events/${file}`)];
|
||||
});
|
||||
}
|
||||
|
@ -37,6 +38,7 @@ export default class Client extends eris.Client {
|
|||
// eslint-disable-next-line new-cap
|
||||
const command: Command = new (require(`${__dirname}/../commands/${file}`).default)(this);
|
||||
this.commands.add(command.name, command);
|
||||
this.util.signale.success(`Successfully loaded command: ${command.name}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
import { Member, Message, Guild } from 'eris';
|
||||
import { Client, Command } from '.';
|
||||
import signale from 'signale';
|
||||
import { Member, Message, Guild, PrivateChannel, GroupChannel } from 'eris';
|
||||
import { Client, Command, RichEmbed } from '.';
|
||||
import { statusMessages as emotes } from '../configs/emotes.json';
|
||||
|
||||
export default class Util {
|
||||
public client: Client;
|
||||
|
||||
public signale: signale.Signale;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
this.signale = signale;
|
||||
this.signale.config({
|
||||
displayDate: true,
|
||||
displayTimestamp: true,
|
||||
displayFilename: true,
|
||||
});
|
||||
}
|
||||
|
||||
get emojis() {
|
||||
|
@ -51,4 +60,33 @@ export default class Util {
|
|||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {
|
||||
try {
|
||||
this.signale.error(error);
|
||||
const info = { content: `\`\`\`js\n${error.stack}\n\`\`\``, embed: null };
|
||||
if (message) {
|
||||
const embed = new RichEmbed();
|
||||
embed.setColor('FF0000');
|
||||
embed.setAuthor(`Error caused by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||
embed.setTitle('Message content');
|
||||
embed.setDescription(message.content);
|
||||
embed.addField('User', `${message.author.mention} (\`${message.author.id}\`)`, true);
|
||||
embed.addField('Channel', message.channel.mention, true);
|
||||
let guild: string;
|
||||
if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) guild = '@me';
|
||||
else guild = message.channel.guild.id;
|
||||
embed.addField('Message link', `[Click here](https://discordapp.com/channels/${guild}/${message.channel.id}/${message.id})`, true);
|
||||
embed.setTimestamp(new Date(message.timestamp));
|
||||
info.embed = embed;
|
||||
}
|
||||
await this.client.createMessage('595788220764127272', info);
|
||||
const msg = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (command) this.resolveCommand(msg).then((c) => { c.cmd.enabled = false; });
|
||||
if (message) message.channel.createMessage(`***${this.emojis.ERROR} An unexpected error has occured - please contact a Faculty Marshal.${command ? ' This command has been disabled.' : ''}***`);
|
||||
} catch (err) {
|
||||
this.signale.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue