Improve exec command

This commit is contained in:
Dragon Fire
2020-09-15 15:14:38 -04:00
parent 1ac4068268
commit 222ddc83a3
2 changed files with 15 additions and 10 deletions
+14 -9
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const { execSync } = require('child_process');
const { stripIndents } = require('common-tags');
module.exports = class ExecCommand extends Command {
constructor(client) {
@@ -22,14 +22,19 @@ module.exports = class ExecCommand extends Command {
});
}
async run(msg, { command }) {
const results = await this.exec(command);
return msg.code('sh', results);
run(msg, { command }) {
const results = this.exec(command);
return msg.reply(stripIndents`
_${results.err ? 'Successfully executed.' : 'An error occurred:'}_
\`\`\`sh
${results.std}
\`\`\`
`);
}
async exec(command) {
const { stdout, stderr } = await exec(command);
if (stderr) return stderr.trim();
return stdout.trim();
exec(command) {
const { stdout, stderr } = execSync(command);
if (stderr) return { err: true, std: stderr.trim() };
return { err: false, std: stdout.trim() };
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.24.2",
"version": "119.24.3",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {