transporter -> logger

This commit is contained in:
Erik 2020-04-12 15:34:26 +03:00
parent 66224698fc
commit c5d6e0c545
2 changed files with 62 additions and 12 deletions

View File

@ -0,0 +1,62 @@
const chalk = require('chalk');
class Logger {
constructor(client) {
this.client = client;
this.client.hooker.hook('ready', () => {
this.transport(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${this.client.guilds.size} guild${this.client.guilds.size === 1 ? '' : 's'}`)}.`, { embed: true, type: 'SUCCESS' });
});
this.client.hooker.hook('componentUpdate', ({ component, type }) => {
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`);
});
this.client.hooker.hook('reconnect', () => {
this.warn(`Shard is reconnecting.`, { embed: true });
});
}
async transport(message = 'N/A', opts = {}) {
process.send({ message, ...opts });
}
/* Quick & Dirty Functions */
log(message, opts = {}) {
this.transport(message, { ...opts, type: 'LOG' });
}
info(message, opts = {}) {
this.transport(message, { ...opts, type: 'INFO' });
}
warn(message, opts = {}) {
this.transport(message, { ...opts, type: 'WARN' });
}
debug(message, opts = {}) {
this.transport(message, { ...opts, type: 'DEBUG' });
}
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'
}
};

View File

@ -1,12 +0,0 @@
class Transporter {
constructor(manager) {
this.manager = manager;
}
}
module.exports = Transporter;