From b48ed4874df9fea82f0fdf24ba3db78db020b73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20Hlavat=C3=BD?= Date: Mon, 18 May 2026 15:20:47 +0200 Subject: [PATCH] markdown juan --- src/tg/bot.deno.ts | 37 ++++++++++++++++++++++++++++++++----- src/tg/utils.deno.ts | 5 +++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/tg/bot.deno.ts b/src/tg/bot.deno.ts index d471cf7..7cd6939 100644 --- a/src/tg/bot.deno.ts +++ b/src/tg/bot.deno.ts @@ -939,11 +939,38 @@ Analyze this conversation. What's going on? Who are the key players? Give your h console.log(`Juan reply: ${text.slice(0, 100)}...`); - yield await tgCall({ - chat_id: data.message.chat.id, - reply_to_message_id: data.message.message_id, - text, - }); + // Escape for MarkdownV2 + const escaped = text.replaceAll("\\", "\\\\") + .replaceAll("`", "\\`") + .replaceAll("_", "\\_") + .replaceAll("*", "\\*") + .replaceAll("[", "\\[") + .replaceAll("]", "\\]") + .replaceAll("(", "\\(") + .replaceAll(")", "\\)") + .replaceAll("~", "\\~") + .replaceAll(">", "\\>") + .replaceAll("#", "\\#") + .replaceAll("+", "\\+") + .replaceAll("-", "\\-") + .replaceAll("=", "\\=") + .replaceAll("|", "\\|") + .replaceAll("{", "\\{") + .replaceAll("}", "\\}") + .replaceAll("!", "\\!") + .replaceAll(".", "\\."); + + yield await tgCall( + { + chat_id: data.message.chat.id, + reply_to_message_id: data.message.message_id, + parse_mode: "MarkdownV2", + text: escaped, + }, + "sendMessage", + 0, + true, // skipBudget (bypass silencing & truncation) + ); } catch (e: any) { console.error(`handleAnalysis error:`, e); yield await tgCall({ diff --git a/src/tg/utils.deno.ts b/src/tg/utils.deno.ts index 03e2a6f..7765c19 100644 --- a/src/tg/utils.deno.ts +++ b/src/tg/utils.deno.ts @@ -67,14 +67,15 @@ export async function tgCall( options: any, endpoint = "sendMessage", retryCount = 0, + skipBudget = false, ): Promise { - if (shutUpState.shut) { + if (!skipBudget && shutUpState.shut) { await new Promise((unShutUp) => shutUpState.up.push(unShutUp)); } if (endpoint == "sendMessage") { options.chat_id ??= MAIN_CHAT_ID; - if (options.text) { + if (options.text && !skipBudget) { if (options.text.length <= budget) { budget -= options.text.length; } else if (budget <= blabla.length) {