Controller

This commit is contained in:
Erik 2022-11-09 11:20:06 +02:00
parent f2f62ec145
commit b0828f049b
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 10 additions and 3 deletions

View File

@ -49,15 +49,21 @@ class Controller extends EventEmitter {
async init () {
this.logger.info(`Initialising Controller`);
const { shardCount = 1, shardOptions = {}, serverOptions = {} } = this._options;
const { shardCount = 1, shardOptions = {}, serverOptions = {}, logger = {}, discord = {}, databases = {} } = this._options;
this.logger.info(`Spawning ${shardCount} shards`);
const promises = [];
for (let i = 0; i < shardCount; i++) {
const shard = new Shard(this, i, { serverOptions, ...shardOptions, env: this._options.env, path: this.filePath });
const shard = new Shard(this, i, { serverOptions: { ...serverOptions, logger, discord, databases }, ...shardOptions, env: this._options.env, path: this.filePath });
this.logger.attach(shard);
this._setListeners(shard);
this.shards.set(i, shard);
promises.push(shard.spawn());
// setTimeout(() => {
// shard.kill();
// }, 10_000);
}
await Promise.all(promises);
@ -66,6 +72,7 @@ class Controller extends EventEmitter {
}
_handleMessage (shard, msg) {
if (msg._logger) return;
this.logger.debug(`Message from ${shard.id}: ${inspect(msg)}`);
}

View File

@ -121,7 +121,7 @@ class Shard extends EventEmitter {
}
}
this.emit('message', this, message);
this.emit('message', message);
}