galactic-bot/structure/client/Logger.js

75 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-04-12 14:34:26 +02:00
const chalk = require('chalk');
const Constants = {
ComponentTypes: {
LOAD: 'loaded',
UNLOAD: 'unloaded',
RELOAD: 'reloaded',
ENABLE: 'enabled',
DISABLE: 'disabled'
}
};
2020-04-12 14:34:26 +02:00
class Logger {
constructor(client) {
this.client = client;
2020-04-13 22:38:10 +02:00
this.client.eventHooker.hook('ready', () => {
2020-04-14 05:25:17 +02:00
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'}`)}.`);
2020-04-12 14:34:26 +02:00
});
2020-04-13 22:38:10 +02:00
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
2020-04-12 14:34:26 +02:00
});
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)}.`);
});
2020-04-12 14:34:26 +02:00
}
async transport(message = 'N/A', opts = {}) {
process.send({ _logger: true, message, ...opts });
2020-04-12 14:34:26 +02:00
}
/* Quick & Dirty Functions */
2020-04-13 22:38:10 +02:00
silly(message, opts = {}) {
this.transport(message, { ...opts, type: 'silly' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
debug(message, opts = {}) {
this.transport(message, { ...opts, type: 'debug' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
verbose(message, opts = {}) {
this.transport(message, { ...opts, type: 'verbose' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
info(message, opts = {}) {
this.transport(message, { ...opts, type: 'info' });
}
warn(message, opts = {}) {
this.transport(message, { ...opts, type: 'warn' });
2020-04-12 14:34:26 +02:00
}
error(message, opts = {}) {
2020-04-13 22:38:10 +02:00
this.transport(message, { ...opts, type: 'error' });
2020-04-12 14:34:26 +02:00
}
}
module.exports = Logger;