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

This commit is contained in:
2026-04-02 21:51:01 +07:00
parent 75f5d4cea4
commit 8be26418b1
2 changed files with 54 additions and 1 deletions

View File

@@ -43,6 +43,20 @@ def build_actor_line(actor: dict, state: dict, config: dict) -> str:
return line
def build_actor_fragment(actor: dict, state: dict, config: dict) -> str:
actor_state = state.get("actors", {})
status_labels = {**DEFAULT_STATUS_LABELS, **config.get("status_labels", {})}
current = actor_state.get(actor["key"], {})
status = current.get("status", actor.get("default_status", "backstage"))
phrase = current.get("phrase", actor.get("phrases", {}).get(status, ""))
label = status_labels.get(status, status)
fragment = f"{escape(label)}."
if phrase:
fragment = f"{fragment}\n {escape(phrase)}"
return fragment
def build_actor_lines(config: dict, state: dict, skip_keys: set[str] | None = None) -> str:
actor_lines: list[str] = []
skip_keys = skip_keys or set()
@@ -66,8 +80,18 @@ def replace_actor_placeholders(template: str, config: dict, state: dict) -> tupl
if actor is None:
return match.group(0)
used_keys.add(actor["key"])
line_start = template.rfind("\n", 0, match.start()) + 1
line_end = template.find("\n", match.end())
if line_end == -1:
line_end = len(template)
line_text = template[line_start:line_end]
if line_text.strip().lower() == match.group(0).strip().lower():
return build_actor_line(actor, state, config)
return build_actor_fragment(actor, state, config)
return ACTOR_PLACEHOLDER_RE.sub(repl, template), used_keys

View File

@@ -64,3 +64,32 @@ def test_build_channel_text_supports_per_actor_placeholders() -> None:
assert text.count("<b>ASTAT</b>") == 1
assert text.count("<b>MARI</b>") == 1
def test_build_channel_text_inlines_actor_fragment_without_duplication() -> None:
config = {
"template_text": (
'🌟 <a href="https://t.me/liebe"><b>LIEBE</b></a> she/her {{actor:liebe}}\n'
'🌟 <a href="https://t.me/victor"><b>VICTOR</b></a> tech bot'
),
"actors": [
{
"key": "liebe",
"display_name": "LIEBE",
"display_html": "<b>LIEBE</b>",
"link": "https://t.me/liebe",
"pronouns": "she/her",
"meta_html": " she/her ",
"emoji": "🌟",
"default_status": "backstage",
"phrases": {"backstage": "в закулисье."},
}
],
}
state = {"actors": {}}
text = build_channel_text(config, state)
assert text.count("<b>LIEBE</b>") == 1
assert "she/her в закулисье." in text
assert "в закулисье." in text