diff options
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/modules/assistant.py | 4 | ||||
| -rw-r--r-- | deckit/server.py | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/deckit/modules/assistant.py b/deckit/modules/assistant.py index f0b3947..4355cfa 100644 --- a/deckit/modules/assistant.py +++ b/deckit/modules/assistant.py @@ -127,6 +127,9 @@ def qarma_args(item, kinds): def make(cfg: dict) -> Module: shell = os.path.expanduser(cfg.get("assistant", {}).get("shell", "")) + face = cfg.get("assistant", {}).get("face") or None + if not (isinstance(face, list) and len(face) == 3 and all(isinstance(v, (int, float)) for v in face)): + face = None # [centre x, centre y, size] in the background image, else a plain circle lock = threading.Lock() # guards st send_lock = threading.Lock() # one writer on the socket at a time voice_lock = threading.Lock() @@ -201,6 +204,7 @@ def make(cfg: dict) -> Module: out = json.loads(json.dumps(st)) # a copy: the reader keeps writing out["wanted"] = wanted() out["hears"] = hears(st["models"], out["wanted"]) + out["face"] = face return out def model(body): diff --git a/deckit/server.py b/deckit/server.py index 9dd5229..f3e1976 100644 --- a/deckit/server.py +++ b/deckit/server.py @@ -112,9 +112,13 @@ def art(): return None -def background(): - """The Assistant tab's backdrop, `[assistant] background`; None when unset.""" - name = CFG.get("assistant", {}).get("background", "") +# /api/<route> -> the [assistant] key naming a local image to serve there. +CONFIG_IMAGES = {"bg": "background", "avatar": "user_avatar"} + + +def config_image(key): + """The Assistant tab's backdrop or the user's avatar; None when unset.""" + name = CFG.get("assistant", {}).get(key, "") path = Path(name).expanduser() try: return (path.read_bytes(), mimetypes.guess_type(path)[0] or "image/jpeg") if name else None @@ -208,8 +212,8 @@ class Handler(BaseHTTPRequestHandler): if len(parts) == 2 and parts[1] == "art": image = art() return self._send(200, image[0], image[1], cache=True) if image else self._send(404) - if len(parts) == 2 and parts[1] == "bg": - image = background() + if len(parts) == 2 and parts[1] in CONFIG_IMAGES: + image = config_image(CONFIG_IMAGES[parts[1]]) return self._send(200, image[0], image[1], cache=True) if image else self._send(404) if len(parts) == 4 and parts[2] == "image": try: |
