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 Command = require('../../structures/Command');
const { promisify } = require('util'); const { execSync } = require('child_process');
const exec = promisify(require('child_process').exec); const { stripIndents } = require('common-tags');
module.exports = class ExecCommand extends Command { module.exports = class ExecCommand extends Command {
constructor(client) { constructor(client) {
@@ -22,14 +22,19 @@ module.exports = class ExecCommand extends Command {
}); });
} }
async run(msg, { command }) { run(msg, { command }) {
const results = await this.exec(command); const results = this.exec(command);
return msg.code('sh', results); return msg.reply(stripIndents`
_${results.err ? 'Successfully executed.' : 'An error occurred:'}_
\`\`\`sh
${results.std}
\`\`\`
`);
} }
async exec(command) { exec(command) {
const { stdout, stderr } = await exec(command); const { stdout, stderr } = execSync(command);
if (stderr) return stderr.trim(); if (stderr) return { err: true, std: stderr.trim() };
return stdout.trim(); return { err: false, std: stdout.trim() };
} }
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "119.24.2", "version": "119.24.3",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {