12312421
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 20:36:20 +07:00
parent ef40fc25ee
commit c286039df7
5 changed files with 405 additions and 77 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from html import escape
DEFAULT_STATUS_LABELS = {
"open": "исполняет роль",
@@ -9,24 +11,30 @@ DEFAULT_STATUS_LABELS = {
}
def _get_block(config: dict, html_key: str, plain_key: str) -> str:
html_value = config.get(html_key, "").strip()
if html_value:
return html_value
plain_value = config.get(plain_key, "").strip()
if plain_value:
return escape(plain_value)
return ""
def build_channel_text(config: dict, state: dict) -> str:
parts: list[str] = []
header = config.get("header", "").strip()
if header:
parts.append(header)
intro_links = config.get("intro_links", "").strip()
if intro_links:
parts.append(intro_links)
projects = config.get("projects_block", "").strip()
if projects:
parts.append(projects)
actors_title = config.get("actors_title", "").strip()
if actors_title:
parts.append(actors_title)
for html_key, plain_key in (
("header_html", "header"),
("intro_links_html", "intro_links"),
("projects_block_html", "projects_block"),
("actors_title_html", "actors_title"),
):
block = _get_block(config, html_key, plain_key)
if block:
parts.append(block)
actor_lines: list[str] = []
actor_state = state.get("actors", {})
@@ -37,22 +45,29 @@ def build_channel_text(config: dict, state: dict) -> str:
phrase = current.get("phrase", actor.get("phrases", {}).get(status, ""))
label = status_labels.get(status, status)
emoji = actor.get("emoji_html") or escape(actor.get("emoji", ""))
name_html = actor.get("display_html") or escape(actor["display_name"])
meta_html = actor.get("meta_html")
if not meta_html:
meta_html = f" {escape(actor['pronouns'])} "
line = (
f'{actor["emoji"]} {actor["display_name"]} ({actor["link"]}) '
f'{actor["pronouns"]} {label}.'
f'{emoji} <a href="{escape(actor["link"], quote=True)}"><b>{name_html}</b></a>'
f"{meta_html}{escape(label)}."
)
if phrase:
line = f"{line}\n {phrase}"
line = f"{line}\n {escape(phrase)}"
actor_lines.append(line)
actor_lines.extend(config.get("static_actor_lines_html", []))
parts.append("\n".join(actor_lines))
legend = config.get("legend", "").strip()
if legend:
parts.append(legend)
footer = config.get("footer", "").strip()
if footer:
parts.append(footer)
for html_key, plain_key in (
("legend_html", "legend"),
("footer_html", "footer"),
):
block = _get_block(config, html_key, plain_key)
if block:
parts.append(block)
return "\n\n".join(part for part in parts if part)