21
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user