debug line test
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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.",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
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("reminder", ["Medis."])
|
||||
text = random.choice(choices)
|
||||
if fmt:
|
||||
try:
|
||||
text = text.format(**fmt)
|
||||
except (KeyError, IndexError):
|
||||
pass
|
||||
return text
|
||||
Reference in New Issue
Block a user