2020-04-13 23:29:08 +02:00
|
|
|
const { EventEmitter } = require('events');
|
2020-04-08 16:27:34 +02:00
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
const ShardManager = require('./middleware/ShardManager.js');
|
|
|
|
const StorageManager = require('./storage/StorageManager.js');
|
2020-04-13 22:38:10 +02:00
|
|
|
const Logger = require('./middleware/logger/Logger.js');
|
2020-04-08 16:01:31 +02:00
|
|
|
|
|
|
|
class Manager extends EventEmitter {
|
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
constructor(options) {
|
|
|
|
|
2020-04-09 16:30:52 +02:00
|
|
|
super();
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
this.shardManager = new ShardManager('./structure/client/DiscordClient.js', options);
|
2020-04-14 08:41:42 +02:00
|
|
|
this.logger = new Logger(this);
|
2020-04-08 16:27:34 +02:00
|
|
|
this.storageManager = new StorageManager(this, options.storage)
|
|
|
|
.initialize();
|
|
|
|
|
|
|
|
this._built = false;
|
2020-04-14 10:26:59 +02:00
|
|
|
|
|
|
|
this.shardManager.on('message', this._handleMessage.bind(this));
|
2020-04-13 23:29:08 +02:00
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
}
|
2020-04-13 23:29:08 +02:00
|
|
|
|
2020-04-14 10:26:59 +02:00
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
async build() {
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
await this.shardManager.spawn();
|
2020-04-09 16:30:52 +02:00
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
this._built = true;
|
|
|
|
|
|
|
|
}
|
2020-04-08 16:01:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
|
|
|
|
|
2020-04-08 16:01:31 +02:00
|
|
|
module.exports = Manager;
|