From 80e706cc81f3a3ce610c3912be6ea9fcf825916c Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 6 May 2024 01:05:02 -0400 Subject: [PATCH] Fix --- commands/util/eval.js | 10 +++++----- commands/util/exec.js | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/commands/util/eval.js b/commands/util/eval.js index 614499dc..f249e8f2 100644 --- a/commands/util/eval.js +++ b/commands/util/eval.js @@ -77,8 +77,8 @@ module.exports = class EvalCommand extends Command { } } - makeResultMessages(result, hrDiff, input = null, lang = 'javascript', inspect = true) { - const inspected = (inspect ? util.inspect(result, { depth: 0 }) : result) + makeResultMessages(result, hrDiff, input = null) { + const inspected = util.inspect(result, { depth: 0 }) .replace(nlPattern, '\n') .replace(this.sensitivePattern, '--snip--'); const split = inspected.split('\n'); @@ -87,19 +87,19 @@ module.exports = class EvalCommand extends Command { const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== '\'' ? split[split.length - 1] : inspected[last]; - const prepend = `\`\`\`${lang}\n${prependPart}\n`; + const prepend = `\`\`\`javascript\n${prependPart}\n`; const append = `\n${appendPart}\n\`\`\``; if (input) { return Util.splitMessage(tags.stripIndents` *Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* - \`\`\`${lang} + \`\`\`javascript ${inspected} \`\`\` `, { maxLength: 1900, prepend, append }); } else { return Util.splitMessage(tags.stripIndents` *Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* - \`\`\`${lang} + \`\`\`javascript ${inspected} \`\`\` `, { maxLength: 1900, prepend, append }); diff --git a/commands/util/exec.js b/commands/util/exec.js index 6ea1e6f0..853693cb 100644 --- a/commands/util/exec.js +++ b/commands/util/exec.js @@ -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 }); + } };