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

This commit is contained in:
2026-04-02 18:04:04 +07:00
commit 02afbd23ec
31 changed files with 2624 additions and 0 deletions

58
session_bot/render.py Normal file
View File

@@ -0,0 +1,58 @@
from __future__ import annotations
DEFAULT_STATUS_LABELS = {
"open": "исполняет роль",
"backstage": "в закулисье",
"delay": "задержки",
"rest": "антракт",
}
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)
actor_lines: list[str] = []
actor_state = state.get("actors", {})
status_labels = {**DEFAULT_STATUS_LABELS, **config.get("status_labels", {})}
for actor in config["actors"]:
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)
line = (
f'{actor["emoji"]} {actor["display_name"]} ({actor["link"]}) '
f'{actor["pronouns"]} {label}.'
)
if phrase:
line = f"{line}\n {phrase}"
actor_lines.append(line)
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)
return "\n\n".join(part for part in parts if part)