Resolve user shortcuts and managerEval

This commit is contained in:
Erik 2020-08-14 17:13:29 +03:00
parent 538d197f94
commit ff544dd57b

View File

@ -40,6 +40,8 @@ class DiscordClient extends Client {
//TODO: Default config for users and guilds. //TODO: Default config for users and guilds.
this._defaultConfig = null; this._defaultConfig = null;
this._evals = new Map();
process.on('message', this._handleMessage.bind(this)); process.on('message', this._handleMessage.bind(this));
} }
@ -70,9 +72,41 @@ class DiscordClient extends Client {
} }
async resolveUsers() {
return this.resolver.resolveUsers(...arguments);
}
async resolveUser() {
return this.resolver.resolveUser(...arguments);
}
async _handleMessage(message) { async _handleMessage(message) {
//Handle misc. messages. //Handle misc. messages.
if (message._evalResult) this.evalResult(message);
}
async managerEval(script) {
return new Promise((resolve, reject) => {
this._evals.set(script, { resolve, reject });
process.send({ _mEval: true, script });
});
}
evalResult({ script, result, error }) {
const promise = this._evals.get(script);
if (result) promise.resolve(result);
else promise.reject(error);
this._evals.delete(script);
} }
get defaultConfig() { get defaultConfig() {