forked from Galactic/galactic-bot
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
const chalk = require('chalk');
|
|
|
|
const Constants = {
|
|
ComponentTypes: {
|
|
LOAD: 'loaded',
|
|
UNLOAD: 'unloaded',
|
|
RELOAD: 'reloaded',
|
|
ENABLE: 'enabled',
|
|
DISABLE: 'disabled'
|
|
}
|
|
};
|
|
|
|
class Logger {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
|
|
this.client.eventHooker.hook('ready', () => {
|
|
const guilds = this.client.guilds.cache.size;
|
|
this.info(`${chalk.bold('[CLIEN]')} 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(`${chalk.bold('[REGIS]')} Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`); //eslint-disable-line no-use-before-define
|
|
});
|
|
|
|
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('[COMMA]')} ${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; |