mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
allow passing a function to shard eval (#2193)
This commit is contained in:
@@ -175,8 +175,8 @@ class Shard extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluates a script on the shard, in the context of the {@link Client}.
|
* Evaluates a script or function on the shard, in the context of the {@link Client}.
|
||||||
* @param {string} script JavaScript to run on the shard
|
* @param {string|Function} script JavaScript to run on the shard
|
||||||
* @returns {Promise<*>} Result of the script execution
|
* @returns {Promise<*>} Result of the script execution
|
||||||
*/
|
*/
|
||||||
eval(script) {
|
eval(script) {
|
||||||
@@ -191,7 +191,8 @@ class Shard extends EventEmitter {
|
|||||||
};
|
};
|
||||||
this.process.on('message', listener);
|
this.process.on('message', listener);
|
||||||
|
|
||||||
this.send({ _eval: script }).catch(err => {
|
const _eval = typeof script === 'function' ? `(${script})(this)` : script;
|
||||||
|
this.send({ _eval }).catch(err => {
|
||||||
this.process.removeListener('message', listener);
|
this.process.removeListener('message', listener);
|
||||||
this._evals.delete(script);
|
this._evals.delete(script);
|
||||||
reject(err);
|
reject(err);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ class ShardClientUtil {
|
|||||||
*/
|
*/
|
||||||
broadcastEval(script) {
|
broadcastEval(script) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
script = typeof script !== 'function' ? `(${script})(this)` : script;
|
||||||
const listener = message => {
|
const listener = message => {
|
||||||
if (!message || message._sEval !== script) return;
|
if (!message || message._sEval !== script) return;
|
||||||
process.removeListener('message', listener);
|
process.removeListener('message', listener);
|
||||||
|
|||||||
Reference in New Issue
Block a user