79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
const chalk = require('chalk');
|
|
|
|
class Logger {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
|
|
this.client.eventHooker.hook('ready', () => {
|
|
const guilds = this.client.guilds.cache.size;
|
|
this.info(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${guilds} guild${guilds === 1 ? '' : 's'}`)}.`);
|
|
});
|
|
|
|
this.client.eventHooker.hook('componentUpdate', ({ component, type }) => {
|
|
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`); //eslint-disable-line no-use-before-define
|
|
});
|
|
|
|
this.client.eventHooker.hook('reconnect', () => {
|
|
this.warn(`Shard is reconnecting.`);
|
|
});
|
|
|
|
this.client.eventHooker.hook('guildCreate', (guild) => {
|
|
this.debug(`${chalk.bold('[GUILD]')} Joined guild ${chalk.bold(guild.name)} (${guild.id}).`);
|
|
});
|
|
|
|
this.client.eventHooker.hook('guildDelete', (guild) => {
|
|
this.debug(`${chalk.bold('[GUILD]')} Left guild ${chalk.bold(guild.name)} (${guild.id}).`);
|
|
});
|
|
|
|
this.client.eventHooker.hook('commandExecute', (message) => {
|
|
this.debug(`${chalk.bold('[EXECU]')} ${message.author.tag} (${message.author.id}) executed command ${chalk.bold(message.command.moduleResolveable)}.`);
|
|
});
|
|
|
|
}
|
|
|
|
async transport(message = 'N/A', opts = {}) {
|
|
process.send({ _logger: true, message, ...opts });
|
|
}
|
|
|
|
/* Quick & Dirty Functions */
|
|
|
|
silly(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'silly' });
|
|
}
|
|
|
|
debug(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'debug' });
|
|
}
|
|
|
|
verbose(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'verbose' });
|
|
}
|
|
|
|
info(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'info' });
|
|
}
|
|
|
|
warn(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'warn' });
|
|
}
|
|
|
|
error(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'error' });
|
|
}
|
|
|
|
|
|
}
|
|
|
|
module.exports = Logger;
|
|
|
|
const Constants = {
|
|
ComponentTypes: {
|
|
LOAD: 'loaded',
|
|
UNLOAD: 'unloaded',
|
|
RELOAD: 'reloaded',
|
|
ENABLE: 'enabled',
|
|
DISABLE: 'disabled'
|
|
}
|
|
}; |