2023-03-19 05:10:48 +00:00
|
|
|
import { clean, htmlescape } from "../../utils/misc.js";
|
2023-03-15 14:09:09 +00:00
|
|
|
import * as util from "util";
|
|
|
|
import { exec as baseExec } from "child_process";
|
|
|
|
const exec = util.promisify(baseExec);
|
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
|
|
|
|
class ExecCommand 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 exec!";
|
|
|
|
}
|
2023-03-17 00:23:01 +00:00
|
|
|
// await this.acknowledge();
|
2023-03-15 14:09:09 +00:00
|
|
|
const code = this.options.cmd ?? this.args.join(" ");
|
|
|
|
try {
|
|
|
|
const execed = await exec(code);
|
2023-03-19 05:10:48 +00:00
|
|
|
if (execed.stderr) return { html: `<pre><code>${htmlescape(await clean(execed.stderr))}</code></pre>` };
|
2023-03-15 14:09:09 +00:00
|
|
|
const cleaned = await clean(execed.stdout);
|
2023-03-15 14:57:57 +00:00
|
|
|
const sendString = `${cleaned}`;
|
2023-03-17 05:47:51 +00:00
|
|
|
if (sendString.length >= 4000) {
|
2023-03-15 14:09:09 +00:00
|
|
|
return {
|
|
|
|
text: "The result was too large, so here it is as a file:",
|
|
|
|
file: cleaned,
|
|
|
|
name: "result.txt"
|
|
|
|
};
|
|
|
|
} else {
|
2023-03-19 05:10:48 +00:00
|
|
|
return { html: "<pre><code>"+htmlescape(sendString)+"</code></pre>" };
|
2023-03-15 14:09:09 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2023-03-15 14:57:57 +00:00
|
|
|
return `\`ERROR\` ${await clean(err)}`;
|
2023-03-15 14:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static flags = [{
|
|
|
|
name: "cmd",
|
|
|
|
type: 3,
|
|
|
|
description: "The command to execute",
|
|
|
|
required: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
static description = "Executes a shell command";
|
|
|
|
static aliases = ["runcmd"];
|
|
|
|
static arguments = ["[command]"];
|
|
|
|
static adminOnly = true;
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default ExecCommand;
|