galactic-bot/Manager.js

41 lines
950 B
JavaScript

const { EventEmitter } = require('events');
const ShardManager = require('./middleware/ShardManager.js');
const Logger = require('./middleware/logger/Logger.js');
class Manager extends EventEmitter {
constructor(options) {
super();
this.shardManager = new ShardManager('./structure/client/DiscordClient.js', options);
this.logger = new Logger(this);
this._built = false;
this.shardManager.on('message', this._handleMessage.bind(this));
// this.on('built', () => {
// this.shardManager.broadcast({ _built: true });
// });
}
_handleMessage(shard, message) {
if(message._logger) return this.logger._handleMessage(shard, message);
if(message._webhook) return undefined; //todo
}
async build() {
await this.shardManager.spawn();
this._built = true;
this.emit('built');
}
}
module.exports = Manager;