From 75f5d4cea43307f705291d7898d02b6ada2b330a Mon Sep 17 00:00:00 2001 From: Verum Date: Thu, 2 Apr 2026 21:44:58 +0700 Subject: [PATCH] 21 --- session_bot/bot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/session_bot/bot.py b/session_bot/bot.py index d84944c..5ce2c43 100644 --- a/session_bot/bot.py +++ b/session_bot/bot.py @@ -140,6 +140,17 @@ def normalize_template_placeholders(template: str) -> str: return normalized +def sanitize_template_html(template: str) -> str: + # Some forwarded/copied premium emoji arrive as X. + # Bots often cannot reuse those identifiers, so keep only the visible fallback text. + return re.sub( + r"]*>(.*?)", + lambda match: match.group(1) or "", + template, + flags=re.IGNORECASE | re.DOTALL, + ) + + def validate_template_structure(template: str) -> str | None: normalized = normalize_template_placeholders(template) common_count = normalized.count("{{actors}}") @@ -226,7 +237,7 @@ async def apply_status_update( def save_post_template(state_storage: JsonStateStorage, template: str) -> None: payload = state_storage.load() - payload["template"] = {"text": normalize_template_placeholders(template)} + payload["template"] = {"text": sanitize_template_html(normalize_template_placeholders(template))} state_storage.save(payload)