galactic-bot/structure/client/Logger.js
2020-04-13 14:38:10 -06:00

66 lines
1.6 KiB
JavaScript

const chalk = require('chalk');
class Logger {
constructor(client) {
this.client = client;
this.client.eventHooker.hook('ready', () => {
this.info(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${this.client.guilds.size} guild${this.client.guilds.size === 1 ? '' : 's'}`)}.`);
});
this.client.eventHooker.hook('componentUpdate', ({ component, type }) => {
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`);
});
this.client.eventHooker.hook('reconnect', () => {
this.warn(`Shard is reconnecting.`);
});
}
async transport(message = 'N/A', opts = {}) {
process.send({ 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'
}
};