mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-15 00:12:38 +02:00
Improve exec command
This commit is contained in:
+14
-9
@@ -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
@@ -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": {
|
||||||
|
|||||||
Reference in New Issue
Block a user