2019-11-13 00:09:06 +00:00
|
|
|
const { clean } = require("../utils/misc.js");
|
|
|
|
const util = require("util");
|
|
|
|
const exec = util.promisify(require("child_process").exec);
|
|
|
|
|
|
|
|
exports.run = async (message, args) => {
|
2019-11-15 16:59:50 +00:00
|
|
|
if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can use exec!`;
|
2019-11-13 00:09:06 +00:00
|
|
|
const code = args.join(" ");
|
|
|
|
try {
|
|
|
|
const execed = await exec(code);
|
|
|
|
if (execed.stderr) return `\`ERROR\` \`\`\`xl\n${await clean(execed.stderr)}\n\`\`\``;
|
|
|
|
const cleaned = await clean(execed.stdout);
|
2020-03-27 13:25:04 +00:00
|
|
|
const sendString = `\`\`\`bash\n${cleaned}\n\`\`\``;
|
|
|
|
if (sendString.length >= 2000) {
|
2020-04-12 19:51:48 +00:00
|
|
|
return {
|
|
|
|
text: "The result was too large, so here it is as a file:",
|
2020-03-27 13:25:04 +00:00
|
|
|
file: cleaned,
|
|
|
|
name: "result.txt"
|
2020-04-12 19:51:48 +00:00
|
|
|
};
|
2020-03-27 13:25:04 +00:00
|
|
|
} else {
|
|
|
|
return sendString;
|
|
|
|
}
|
2019-11-13 00:09:06 +00:00
|
|
|
} catch (err) {
|
|
|
|
return `\`ERROR\` \`\`\`xl\n${await clean(err)}\n\`\`\``;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.aliases = ["runcmd"];
|
2019-12-02 20:47:22 +00:00
|
|
|
exports.category = 7;
|
2019-12-05 16:58:46 +00:00
|
|
|
exports.help = "Executes a terminal command";
|
|
|
|
exports.params = "[command]";
|