forked from onlyjasonhere/djs-selfbot-v9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.js
42 lines (37 loc) · 1.18 KB
/
exec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { exec } = require("child_process");
exports.run = async (client, msg, args) => {
const command = args.join(" ");
const outMessage = await msg.channel.send(`Running \`${command}\`...`);
let stdOut = await doExec(command).catch(data=> outputErr(outMessage, data));
stdOut = stdOut.substring(0, 1750);
outMessage.edit(`\`OUTPUT\`
\`\`\`sh
${client.clean(stdOut)}
\`\`\``);
};
exports.conf = {
enabled: true,
guildOnly: false,
aliases: [],
permLevel: 0
};
exports.help = {
name: 'exec',
description: 'Executes a console command.',
usage: 'exec [command]'
};
const outputErr = (msg, stdData) => {
let { stdout, stderr } = stdData;
stderr = stderr ? ["`STDERR`","```sh",client.clean(stderr.substring(0, 800)) || " ","```"] : [];
stdout = stdout ? ["`STDOUT`","```sh",client.clean(stdout.substring(0, stderr ? stderr.length : 2046 - 40)) || " ","```"] : [];
let message = stdout.concat(stderr).join("\n").substring(0, 2000);
msg.edit(message);
};
const doExec = (cmd, opts = {}) => {
return new Promise((resolve, reject) => {
exec(cmd, opts, (err, stdout, stderr) => {
if (err) return reject({ stdout, stderr });
resolve(stdout);
});
});
};