From d1ca268f369e30bec80bd4d1a6a3e68e7d10d87d Mon Sep 17 00:00:00 2001 From: gaoao-3 <140887777+gaoao-3@users.noreply.github.com> Date: Fri, 3 Jan 2025 15:06:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/tools/CodeExecutionTool.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/utils/tools/CodeExecutionTool.js b/utils/tools/CodeExecutionTool.js index 509787d..327373f 100644 --- a/utils/tools/CodeExecutionTool.js +++ b/utils/tools/CodeExecutionTool.js @@ -54,20 +54,29 @@ export class CodeExecutionTool extends AbstractTool { const result = await this.executeCode(code, language, description); console.debug(`[CodeExecutionTool] 执行结果:`, result); - // 构建转发消息 - const { output, explanation, error } = result; - const forwardMsg = []; + // 优化消息构建逻辑 + const messages = []; - if (error) { - forwardMsg.push(`执行出错:\n${error}`); + // 添加代码信息 + messages.push(`执行代码:\n\`\`\`${language}\n${code}\n\`\`\``); + + // 添加执行结果 + if (result.error) { + messages.push(`执行错误:\n\`\`\`\n${result.error}\n\`\`\``); } else { - forwardMsg.push(`执行结果:\n${output}`); - if (explanation) { - forwardMsg.push(`\n代码分析:\n${explanation}`); - } + messages.push(`执行结果:\n\`\`\`\n${result.output}\n\`\`\``); } - e.reply(await common.makeForwardMsg(e, forwardMsg, `${e.sender.card || e.sender.nickname || e.user_id}的代码执行结果`)); + // 添加代码分析 + if (result.explanation) { + messages.push(`代码分析:\n${result.explanation}`); + } + + // 添加执行时间 + messages.push(`执行时间:${new Date(result.executionTime).toLocaleString()}`); + + // 发送转发消息 + e.reply(await common.makeForwardMsg(e, messages, `${e.sender.card || e.sender.nickname || e.user_id}的代码执行结果`)); return result; } catch (error) {