mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix
This commit is contained in:
+14
-2
@@ -1,7 +1,9 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const execAsync = promisify(exec);
|
||||
const { splitMessage } = require('../../util/Util');
|
||||
|
||||
module.exports = class ExecCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -24,8 +26,7 @@ module.exports = class ExecCommand extends Command {
|
||||
|
||||
async run(msg, { command }) {
|
||||
const results = await this.exec(command);
|
||||
const msgs = this.client.registry.commands.get('eval')
|
||||
.makeResultMessages(results.std, results.hrDiff, command, 'sh');
|
||||
const msgs = this.makeResultMessages(results.std, results.hrDiff);
|
||||
if (Array.isArray(msgs)) {
|
||||
return msgs.map(item => msg.reply(item));
|
||||
} else {
|
||||
@@ -44,4 +45,15 @@ module.exports = class ExecCommand extends Command {
|
||||
return { err: true, std: err.stderr.trim(), hrDiff: null };
|
||||
}
|
||||
}
|
||||
|
||||
makeResultMessages(result, hrDiff) {
|
||||
const prepend = `\`\`\`sh\n`;
|
||||
const append = `\n\`\`\``;
|
||||
return splitMessage(stripIndents`
|
||||
*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
||||
\`\`\`sh
|
||||
${result}
|
||||
\`\`\`
|
||||
`, { maxLength: 1900, prepend, append });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user