Fixed shard IPC not working properly

This commit is contained in:
Erik 2023-12-08 13:20:05 +02:00
parent 601f7628b3
commit 5c61eb12e2
5 changed files with 830 additions and 831 deletions

2
@types/Shared.d.ts vendored
View File

@ -38,7 +38,7 @@ export type IPCMessage = {
respawnDelay: number,
timeout: number
},
_mEval?: string,
_mEval?: boolean,
_mEvalResult?: boolean
_logger?: boolean,
_api?: boolean,

View File

@ -269,10 +269,8 @@ class DiscordClient extends Client
script = `(${script})(this, ${JSON.stringify(options.context)})`;
return new Promise((resolve, reject) =>
{
if (!process.send)
return reject(new Error('No parent process'));
this.#evals.set(script as string, { resolve, reject });
process.send({ _mEval: true, script, debug: options.debug || process.env.NODE_ENV === 'development' });
this.#intercom.send('mEval', { script, debug: options.debug ?? process.env.NODE_ENV === 'development' });
});
}

View File

@ -211,7 +211,7 @@ class Controller extends EventEmitter
// this.logger.debug(`New message from ${shard ? `${message._api ? 'api-' : ''}shard ${shard.id}`: 'manager'}: ${inspect(message)}`);
if (message._mEval)
return this.eval(shard, { script: message._mEval, debug: message.debug || false });
return this.eval(shard, { script: message.script!, debug: message.debug || false });
if (message._commands)
return this.#slashCommandManager._handleMessage(message as CommandsDef);
if (message._api)

View File

@ -55,7 +55,8 @@ class Shard extends EventEmitter
this.#env = {
...process.env,
SHARDING_MANAGER: true,
SHARDING_MANAGER: true, // IMPORTANT, SHARD IPC WILL BREAK IF MISSING
SHARDING_MANAGER_MODE: 'process', // IMPORTANT, SHARD IPC WILL BREAK IF MISSING
SHARD_ID: this.#id,
SHARD_COUNT: options.totalShards,
DISCORD_TOKEN: options.token