logger tweaks
This commit is contained in:
parent
815414520b
commit
f1f660f7f9
@ -1,4 +1,5 @@
|
||||
const { Client } = require('discord.js');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const { Logger, Intercom, EventHooker, LocaleLoader, Registry, Dispatcher, Resolver } = require('./client/');
|
||||
const { Observer, Command, Setting, Inhibitor } = require('./interfaces/');
|
||||
@ -9,6 +10,16 @@ const { DefaultGuild } = require('../constants/');
|
||||
const options = require('../../options.json');
|
||||
const RateLimiter = require('./client/RateLimiter');
|
||||
|
||||
const Constants = {
|
||||
ComponentTypes: {
|
||||
LOAD: 'loaded',
|
||||
UNLOAD: 'unloaded',
|
||||
RELOAD: 'reloaded',
|
||||
ENABLE: 'enabled',
|
||||
DISABLE: 'disabled'
|
||||
}
|
||||
};
|
||||
|
||||
class DiscordClient extends Client {
|
||||
|
||||
constructor(options) {
|
||||
@ -18,10 +29,10 @@ class DiscordClient extends Client {
|
||||
...options.discord.clientOptions
|
||||
});
|
||||
|
||||
this.eventHooker = new EventHooker(this);
|
||||
this.dispatcher = new Dispatcher(this);
|
||||
this.intercom = new Intercom(this);
|
||||
this.logger = new Logger(this);
|
||||
this.eventHooker = new EventHooker(this);
|
||||
this.intercom = new Intercom(this);
|
||||
this.dispatcher = new Dispatcher(this);
|
||||
this.localeLoader = new LocaleLoader(this);
|
||||
this.storageManager = new StorageManager(this, options.storage);
|
||||
this.registry = new Registry(this);
|
||||
@ -45,6 +56,8 @@ class DiscordClient extends Client {
|
||||
// }, 1800000); // I think this is 30 minutes. I could be wrong.
|
||||
// });
|
||||
|
||||
this._loadEevents();
|
||||
|
||||
}
|
||||
|
||||
async build() {
|
||||
@ -120,6 +133,50 @@ class DiscordClient extends Client {
|
||||
return this.shard.count === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_loadEevents() {
|
||||
|
||||
this.eventHooker.hook('ready', () => {
|
||||
const guilds = this.guilds.cache.size;
|
||||
this.logger.info(`Client connected to ${chalk.bold(this.user.tag)} with ${chalk.bold(`${guilds} guild${guilds === 1 ? '' : 's'}`)}.`);
|
||||
});
|
||||
|
||||
this.eventHooker.hook('componentUpdate', ({ component, type }) => {
|
||||
this.logger.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`); //eslint-disable-line no-use-before-define
|
||||
});
|
||||
|
||||
this.eventHooker.hook('guildCreate', (guild) => {
|
||||
this.logger.debug(`${chalk.bold('[GUILD]')} Joined guild ${chalk.bold(guild.name)} (${guild.id}).`);
|
||||
});
|
||||
|
||||
this.eventHooker.hook('guildDelete', (guild) => {
|
||||
this.logger.debug(`${chalk.bold('[GUILD]')} Left guild ${chalk.bold(guild.name)} (${guild.id}).`);
|
||||
});
|
||||
|
||||
this.eventHooker.hook('shardDisconect', () => {
|
||||
this.logger.status('Shard disconnected.');
|
||||
});
|
||||
|
||||
this.eventHooker.hook('shardError', (error) => {
|
||||
this.logger.status(`Shard errored:\n${error.stack ?? error}`);
|
||||
});
|
||||
|
||||
this.eventHooker.hook('shardReady', (id, unavailableGuilds) => {
|
||||
this.logger.status(`Shard is ready${unavailableGuilds ? ` with ${chalk.bold(`${[...unavailableGuilds].length} unavailable guilds`)}` : ''}.`);
|
||||
});
|
||||
|
||||
this.eventHooker.hook('shardReconnecting', () => {
|
||||
this.logger.status('Shard is reconnecting.');
|
||||
});
|
||||
|
||||
this.eventHooker.hook('shardResume', () => {
|
||||
this.logger.status('Shard resumed.');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DiscordClient;
|
||||
|
Loading…
Reference in New Issue
Block a user