bot: add eval
This commit is contained in:
parent
4b8172ff71
commit
7335da4dca
1 changed files with 40 additions and 0 deletions
|
@ -2,6 +2,9 @@ const Command = require("../lib/command.js");
|
||||||
const CATEGORY = "bot";
|
const CATEGORY = "bot";
|
||||||
|
|
||||||
const logger = require("npmlog");
|
const logger = require("npmlog");
|
||||||
|
const {inspect} = require("util");
|
||||||
|
|
||||||
|
const {hastebin} = require("../lib/utils.js");
|
||||||
|
|
||||||
const reload = new Command("reload");
|
const reload = new Command("reload");
|
||||||
reload.ownerOnly = true;
|
reload.ownerOnly = true;
|
||||||
|
@ -38,3 +41,40 @@ restart.callback = function () {
|
||||||
return {reaction: "\uD83D\uDD04"};
|
return {reaction: "\uD83D\uDD04"};
|
||||||
};
|
};
|
||||||
hf.registerCommand(restart);
|
hf.registerCommand(restart);
|
||||||
|
|
||||||
|
const _eval = new Command("eval");
|
||||||
|
_eval.elevatedOnly = true;
|
||||||
|
_eval.category = CATEGORY;
|
||||||
|
_eval.helpText = "Evalueates Javascript";
|
||||||
|
_eval.callback = async function (msg, line) {
|
||||||
|
let errored = false;
|
||||||
|
let out;
|
||||||
|
|
||||||
|
try {
|
||||||
|
out = eval(line);
|
||||||
|
if (out && out.then) out = await out;
|
||||||
|
} catch (err) {
|
||||||
|
out = err.message ? err.message : err;
|
||||||
|
errored = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
out = typeof out == "string" ? out : inspect(out, {depth: 0});
|
||||||
|
|
||||||
|
const token = hf.config.token;
|
||||||
|
out = out.replace(
|
||||||
|
new RegExp(token.replace(/\./g, "\\."), "g"),
|
||||||
|
"lol no key 4 u"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (errored) {
|
||||||
|
return ":warning: Output (errored):\n```js\n" + out + "\n```";
|
||||||
|
} else {
|
||||||
|
if (out.toString().length > 1980) {
|
||||||
|
const code = hastebin(out.toString());
|
||||||
|
return `\u2705 Output too long to send in a message: ${hf.config.haste_provider}/${code}`;
|
||||||
|
} else {
|
||||||
|
return "\u2705 Output:\n```js\n" + out + "\n```";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
hf.registerCommand(_eval);
|
||||||
|
|
Loading…
Reference in a new issue