diff --git a/services/communication/atlasbot-configmap.yaml b/services/communication/atlasbot-configmap.yaml index aba33da..034d55e 100644 --- a/services/communication/atlasbot-configmap.yaml +++ b/services/communication/atlasbot-configmap.yaml @@ -17,8 +17,31 @@ data: MODEL = os.environ.get("OLLAMA_MODEL", "qwen2.5-coder:7b-instruct-q4_0") API_KEY = os.environ.get("CHAT_API_KEY", "") BOT_MENTIONS = os.environ.get("BOT_MENTIONS", f"{USER},atlas") - MENTION_LOCALPARTS = [m.strip().lstrip("@") for m in BOT_MENTIONS.split(",") if m.strip()] + SERVER_NAME = os.environ.get("MATRIX_SERVER_NAME", "live.bstein.dev") + MENTION_TOKENS = [m.strip() for m in BOT_MENTIONS.split(",") if m.strip()] + MENTION_LOCALPARTS = [m.lstrip("@").split(":", 1)[0] for m in MENTION_TOKENS] MENTION_RE = re.compile(r"(? str: + t = token.strip() + if not t: + return "" + if t.startswith("@") and ":" in t: + return t + t = t.lstrip("@") + if ":" in t: + return f"@{t}" + return f"@{t}:{SERVER_NAME}" + + MENTION_USER_IDS = {normalize_user_id(t).lower() for t in MENTION_TOKENS if normalize_user_id(t)} + + def is_mentioned(content: dict, body: str) -> bool: + if MENTION_RE.search(body or "") is not None: + return True + mentions = content.get("m.mentions", {}) + user_ids = mentions.get("user_ids", []) + if not isinstance(user_ids, list): + return False + return any(isinstance(uid, str) and uid.lower() in MENTION_USER_IDS for uid in user_ids) def req(method: str, path: str, token: str | None = None, body=None, timeout=60, base: str | None = None): url = (base or BASE) + path @@ -123,7 +146,7 @@ data: # Only respond if bot is mentioned or in a DM joined_count = data.get("summary", {}).get("m.joined_member_count") is_dm = joined_count is not None and joined_count <= 2 - mentioned = MENTION_RE.search(body) is not None + mentioned = is_mentioned(content, body) hist_key = key_for(rid, sender, is_dm) history[hist_key].append(f"{sender}: {body}") history[hist_key] = history[hist_key][-80:] diff --git a/services/communication/atlasbot-deployment.yaml b/services/communication/atlasbot-deployment.yaml index 12f3e30..fbb9b3d 100644 --- a/services/communication/atlasbot-deployment.yaml +++ b/services/communication/atlasbot-deployment.yaml @@ -16,7 +16,7 @@ spec: labels: app: atlasbot annotations: - checksum/atlasbot-configmap: cb29da6de63e087511e1936d41a6d12eff7f43c55cf266d1e71c3c2e14661c7b + checksum/atlasbot-configmap: c57538d33dc02db7aaf7b2f4681f50620c2cbcde8ddc1c51ccb5fa693247b00a spec: nodeSelector: hardware: rpi5