from __future__ import annotations import pathlib import random from typing import Any import yaml from server.settings import settings _pool: dict[str, list[str]] | None = None DEFAULT_MESSAGES: dict[str, list[str]] = { "reminder": ["Zeit für Medis. Dein Gehirn wartet.", "Med-Time. Nicht vergessen."], "success": ["Genommen. Held des Tages.", "Dopamin incoming."], "missed": ["Verpasst. Das Gehirn ist enttäuscht.", "Nächstes Mal vielleicht."], "streak": ["Streak läuft!", "Weiter so, Ausnahme vom ADHS-Gesetz."], "snooze": ["Okay, noch 15 Min. Aber wirklich.", "Snooze aktiviert. Prokrastination approved."], "easter_egg": ["Achievement unlocked!", "Du hast was Seltenes freigeschaltet."], "roast_fallback": [ "Dein Gehirn hat heute schon aufgegeben, bevor du die PIN eingegeben hast.", "Elvanse wartet. Du offenbar auch, aber im falschen Sinne.", ], "motivation_fallback": [ "Dein Gehirn ist nicht kaputt. Es läuft nur auf einem anderen Betriebssystem — ohne Support.", "Du bist nicht faul. Dein Dopamin ist nur gerade in einem Meeting ohne Agenda.", "Heute ist ein guter Tag — oder zumindest einer, an dem Medis existieren.", "ADHS: where focus goes to die. Medis: der Respawn-Button.", "Du schaffst das. Nicht alles, aber Medis. Das zählt.", ], } def load_messages(path: str | None = None) -> dict[str, list[str]]: global _pool if _pool is not None: return _pool p = pathlib.Path(path or settings.messages_path) if p.exists(): raw = yaml.safe_load(p.read_text(encoding="utf-8")) or {} _pool = {**DEFAULT_MESSAGES, **{k: v for k, v in raw.items() if isinstance(v, list)}} else: _pool = DEFAULT_MESSAGES return _pool def pick(category: str, **fmt: Any) -> str: pool = load_messages() choices = pool.get(category) or pool.get("motivation_fallback") or pool.get("reminder", ["Medis."]) text = random.choice(choices) if fmt: try: text = text.format(**fmt) except (KeyError, IndexError): pass return text