21
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 32s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 10s

This commit is contained in:
2026-04-02 21:44:58 +07:00
parent 8fb6da84ae
commit 75f5d4cea4

View File

@@ -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 <tg-emoji emoji-id="...">X</tg-emoji>.
# Bots often cannot reuse those identifiers, so keep only the visible fallback text.
return re.sub(
r"<tg-emoji\b[^>]*>(.*?)</tg-emoji>",
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)