From b0828f049b45825bdaaae8a3ac73d065257afb70 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 9 Nov 2022 11:20:06 +0200 Subject: [PATCH] Controller --- src/controller/Controller.js | 11 +++++++++-- src/controller/Shard.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/controller/Controller.js b/src/controller/Controller.js index 0dda76b..362c6ea 100644 --- a/src/controller/Controller.js +++ b/src/controller/Controller.js @@ -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)}`); } diff --git a/src/controller/Shard.js b/src/controller/Shard.js index 99858d6..c6842e4 100644 --- a/src/controller/Shard.js +++ b/src/controller/Shard.js @@ -121,7 +121,7 @@ class Shard extends EventEmitter { } } - this.emit('message', this, message); + this.emit('message', message); }