2023-03-15 14:09:09 +00:00
|
|
|
import { clean } from "../../utils/misc.js";
|
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
|
|
|
|
class EvalCommand extends Command {
|
2023-03-19 05:10:48 +00:00
|
|
|
static category = "general"
|
2023-03-15 14:09:09 +00:00
|
|
|
async run() {
|
|
|
|
const owners = process.env.OWNER.split(",");
|
2023-03-15 14:12:35 +00:00
|
|
|
if (!owners.includes(this.author)) {
|
2023-03-15 14:09:09 +00:00
|
|
|
this.success = false;
|
|
|
|
return "Only the bot owner can use eval!";
|
|
|
|
}
|
2023-03-17 00:23:01 +00:00
|
|
|
// await this.acknowledge();
|
2023-03-15 14:09:09 +00:00
|
|
|
const code = this.options.code ?? this.args.join(" ");
|
|
|
|
try {
|
|
|
|
let evaled = eval(code);
|
|
|
|
if (evaled?.constructor?.name == "Promise") evaled = await evaled;
|
|
|
|
const cleaned = clean(evaled);
|
|
|
|
const sendString = `\`\`\`js\n${cleaned}\n\`\`\``;
|
|
|
|
if (sendString.length >= 2000) {
|
|
|
|
return {
|
|
|
|
content: "The result was too large, so here it is as a file:",
|
|
|
|
files: [{
|
|
|
|
contents: cleaned,
|
|
|
|
name: "result.txt"
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return sendString;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
let error = err;
|
|
|
|
if (err?.constructor?.name == "Promise") error = await err;
|
|
|
|
return `\`ERROR\` \`\`\`xl\n${clean(error)}\n\`\`\``;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static flags = [{
|
|
|
|
name: "code",
|
|
|
|
type: 3,
|
|
|
|
description: "The code to execute",
|
|
|
|
required: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
static description = "Executes JavaScript code";
|
|
|
|
static aliases = ["run"];
|
|
|
|
static arguments = ["[code]"];
|
|
|
|
static adminOnly = true;
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default EvalCommand;
|