MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / handleContextShow

Function handleContextShow

outdated/gemini/gemini.ts:1399–1434  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

1397}
1398
1399async function handleContextShow(msg: Api.Message): Promise<void> {
1400 const history = JSON.parse(ConfigManager.get(CONFIG_KEYS.GEMINI_CHAT_HISTORY, "[]"));
1401 const isEnabled = ConfigManager.get(CONFIG_KEYS.GEMINI_CONTEXT_ENABLED) === "on";
1402
1403 if (history.length === 0) {
1404 await msg.edit({
1405 text: `<b>对话上下文状态:</b> ${isEnabled ? "已启用" : "已禁用"}\n\n<b>对话历史:</b> 空`,
1406 parseMode: "html"
1407 });
1408 return;
1409 }
1410
1411 let displayText = `<b>对话上下文状态:</b> ${isEnabled ? "已启用" : "已禁用"}\n\n<b>对话历史</b> (${history.length / 2} 轮对话):\n\n`;
1412
1413 const maxRounds = 5;
1414 const startIndex = Math.max(0, history.length - maxRounds * 2);
1415
1416 for (let i = startIndex; i < history.length; i += 2) {
1417 const userMsg = history[i]?.parts?.[0]?.text || "";
1418 const assistantMsg = history[i + 1]?.parts?.[0]?.text || "";
1419
1420 const roundNum = Math.floor(i / 2) + 1;
1421 const truncatedUserMsg = userMsg.length > 100 ? userMsg.substring(0, 100) + "..." : userMsg;
1422 const truncatedAssistantMsg = assistantMsg.length > 200 ? assistantMsg.substring(0, 200) + "..." : assistantMsg;
1423
1424 displayText += `<b>第${roundNum}轮:</b>\n`;
1425 displayText += `<b>Q:</b> ${Utils.escapeHtml(truncatedUserMsg)}\n`;
1426 displayText += `<b>A:</b> ${Utils.escapeHtml(truncatedAssistantMsg)}\n\n`;
1427 }
1428
1429 if (history.length > maxRounds * 2) {
1430 displayText += `<i>... 还有 ${Math.floor((history.length - maxRounds * 2) / 2)} 轮更早的对话</i>`;
1431 }
1432
1433 await msg.edit({ text: displayText, parseMode: "html" });
1434}
1435
1436async function handleTelegraph(msg: Api.Message, args: string[]): Promise<void> {
1437 const subCommand = args[0];

Callers 1

handleGeminiRequestFunction · 0.85

Calls 3

escapeHtmlMethod · 0.80
getMethod · 0.45
editMethod · 0.45

Tested by

no test coverage detected