Something went wrong. Try again.
A Discord bot designed to entertain your server esmbot.net
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import { Buffer } from "node:buffer";import { exec as baseExec } from "node:child_process";import { promisify } from "node:util";import Command from "#cmd-classes/command.js";import { getEnv } from "#utils/runtime.js";import { clean } from "#utils/sanitize.js";/** @import { CommandFlag } from "#utils/types.js" */const exec = promisify(baseExec);
class ExecCommand extends Command { async run() { const owners = getEnv("OWNER")?.split(",") ?? []; if (!owners.includes(this.author.id)) { this.success = false; return this.getString("commands.responses.exec.botOwnerOnly"); } await this.acknowledge(); const code = this.getOptionString("cmd") ?? this.args.join(" "); try { const execed = await exec(code); if (execed.stderr) return `\`${this.getString("errorCaps")}\` \`\`\`xl\n${clean(execed.stderr)}\n\`\`\``; const cleaned = clean(execed.stdout); const sendString = `\`\`\`bash\n${cleaned}\n\`\`\``; if (sendString.length >= 2000) { return { content: this.getString("tooLarge"), files: [ { contents: Buffer.from(cleaned), name: "result.txt", }, ], }; } return sendString; } catch (err) { return `\`${this.getString("errorCaps")}\` \`\`\`xl\n${clean(err)}\n\`\`\``; } }
/** @type {CommandFlag[]} */ static flags = [ { name: "cmd", type: "string", description: "The command to execute", classic: true, required: true, }, ];
static description = "Executes a shell command"; static aliases = ["runcmd"]; static adminOnly = true;}
export default ExecCommand;