123
This commit is contained in:
58
session_bot/render.py
Normal file
58
session_bot/render.py
Normal 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)
|
||||
Reference in New Issue
Block a user