mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 06:42:50 +02:00
Fix
This commit is contained in:
@@ -77,8 +77,8 @@ module.exports = class EvalCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
makeResultMessages(result, hrDiff, input = null, lang = 'javascript', inspect = true) {
|
makeResultMessages(result, hrDiff, input = null) {
|
||||||
const inspected = (inspect ? util.inspect(result, { depth: 0 }) : result)
|
const inspected = util.inspect(result, { depth: 0 })
|
||||||
.replace(nlPattern, '\n')
|
.replace(nlPattern, '\n')
|
||||||
.replace(this.sensitivePattern, '--snip--');
|
.replace(this.sensitivePattern, '--snip--');
|
||||||
const split = inspected.split('\n');
|
const split = inspected.split('\n');
|
||||||
@@ -87,19 +87,19 @@ module.exports = class EvalCommand extends Command {
|
|||||||
const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== '\''
|
const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== '\''
|
||||||
? split[split.length - 1]
|
? split[split.length - 1]
|
||||||
: inspected[last];
|
: inspected[last];
|
||||||
const prepend = `\`\`\`${lang}\n${prependPart}\n`;
|
const prepend = `\`\`\`javascript\n${prependPart}\n`;
|
||||||
const append = `\n${appendPart}\n\`\`\``;
|
const append = `\n${appendPart}\n\`\`\``;
|
||||||
if (input) {
|
if (input) {
|
||||||
return Util.splitMessage(tags.stripIndents`
|
return Util.splitMessage(tags.stripIndents`
|
||||||
*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
||||||
\`\`\`${lang}
|
\`\`\`javascript
|
||||||
${inspected}
|
${inspected}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`, { maxLength: 1900, prepend, append });
|
`, { maxLength: 1900, prepend, append });
|
||||||
} else {
|
} else {
|
||||||
return Util.splitMessage(tags.stripIndents`
|
return Util.splitMessage(tags.stripIndents`
|
||||||
*Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
*Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
||||||
\`\`\`${lang}
|
\`\`\`javascript
|
||||||
${inspected}
|
${inspected}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`, { maxLength: 1900, prepend, append });
|
`, { maxLength: 1900, prepend, append });
|
||||||
|
|||||||
+14
-2
@@ -1,7 +1,9 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
|
const { stripIndents } = require('common-tags');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
const { splitMessage } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class ExecCommand extends Command {
|
module.exports = class ExecCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -24,8 +26,7 @@ module.exports = class ExecCommand extends Command {
|
|||||||
|
|
||||||
async run(msg, { command }) {
|
async run(msg, { command }) {
|
||||||
const results = await this.exec(command);
|
const results = await this.exec(command);
|
||||||
const msgs = this.client.registry.commands.get('eval')
|
const msgs = this.makeResultMessages(results.std, results.hrDiff);
|
||||||
.makeResultMessages(results.std, results.hrDiff, command, 'sh');
|
|
||||||
if (Array.isArray(msgs)) {
|
if (Array.isArray(msgs)) {
|
||||||
return msgs.map(item => msg.reply(item));
|
return msgs.map(item => msg.reply(item));
|
||||||
} else {
|
} else {
|
||||||
@@ -44,4 +45,15 @@ module.exports = class ExecCommand extends Command {
|
|||||||
return { err: true, std: err.stderr.trim(), hrDiff: null };
|
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