Fixed shard IPC not working properly
This commit is contained in:
parent
601f7628b3
commit
5c61eb12e2
2
@types/Shared.d.ts
vendored
2
@types/Shared.d.ts
vendored
@ -38,7 +38,7 @@ export type IPCMessage = {
|
||||
respawnDelay: number,
|
||||
timeout: number
|
||||
},
|
||||
_mEval?: string,
|
||||
_mEval?: boolean,
|
||||
_mEvalResult?: boolean
|
||||
_logger?: boolean,
|
||||
_api?: boolean,
|
||||
|
@ -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' });
|
||||
});
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -209,9 +209,9 @@ class Controller extends EventEmitter
|
||||
if (message._logger)
|
||||
return;
|
||||
// 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)
|
||||
|
@ -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
|
||||
@ -170,7 +171,7 @@ class Shard extends EventEmitter
|
||||
|
||||
// When killing the process, give it an opportonity to gracefully shut down (i.e. clean up DB connections etc)
|
||||
// It simply has to respond with a shutdown message to the shutdown event
|
||||
kill ()
|
||||
kill ()
|
||||
{
|
||||
if (this.#process)
|
||||
{
|
||||
@ -208,7 +209,7 @@ class Shard extends EventEmitter
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
awaitShutdown ()
|
||||
awaitShutdown ()
|
||||
{
|
||||
this.#respawn = false;
|
||||
return new Promise<void>((resolve) =>
|
||||
@ -292,7 +293,7 @@ class Shard extends EventEmitter
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
eval (script: string | Function, context?: object): Promise<unknown>
|
||||
eval (script: string | Function, context?: object): Promise<unknown>
|
||||
{
|
||||
// Stringify the script if it's a Function
|
||||
const _eval = typeof script === 'function' ? `(${script})(this, ${JSON.stringify(context)})` : script;
|
||||
|
Loading…
Reference in New Issue
Block a user