forked from Galactic/galactic-bot
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
const { EventEmitter } = require('events');
|
|
|
|
const ShardManager = require('./middleware/ShardManager.js');
|
|
const StorageManager = require('./storage/StorageManager.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.storageManager = new StorageManager(this, options.storage)
|
|
.initialize();
|
|
|
|
this._built = false;
|
|
|
|
this.shardManager.on('message', this._handleMessage.bind(this));
|
|
|
|
}
|
|
|
|
_handleMessage(shard, message) {
|
|
if(message._logger) return this.logger._handleMessage(shard, message);
|
|
if(message._storage) return this.storageManager._handleStorageRequest(shard, message);
|
|
if(message._webhook) return undefined; //todo
|
|
}
|
|
|
|
async build() {
|
|
|
|
await this.shardManager.spawn();
|
|
|
|
this._built = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Manager; |