atlasbot: recognize prefix mentions

This commit is contained in:
Brad Stein 2026-01-26 15:54:00 -03:00
parent 0ac0f920ca
commit be7846572f
2 changed files with 13 additions and 1 deletions

View File

@ -78,7 +78,7 @@ spec:
- name: BOT_USER - name: BOT_USER
value: atlasbot value: atlasbot
- name: BOT_MENTIONS - name: BOT_MENTIONS
value: atlasbot value: atlasbot,aatlasbot
- name: OLLAMA_URL - name: OLLAMA_URL
value: http://chat-ai-gateway.bstein-dev-home.svc.cluster.local/ value: http://chat-ai-gateway.bstein-dev-home.svc.cluster.local/
- name: OLLAMA_MODEL - name: OLLAMA_MODEL

View File

@ -119,9 +119,21 @@ def normalize_user_id(token: str) -> str:
MENTION_USER_IDS = {normalize_user_id(t).lower() for t in MENTION_TOKENS if normalize_user_id(t)} MENTION_USER_IDS = {normalize_user_id(t).lower() for t in MENTION_TOKENS if normalize_user_id(t)}
def _body_mentions_token(body: str) -> bool:
lower = (body or "").strip().lower()
if not lower:
return False
for token in MENTION_LOCALPARTS:
for prefix in (token, f"@{token}"):
if lower.startswith(prefix + ":") or lower.startswith(prefix + ",") or lower.startswith(prefix + " "):
return True
return False
def is_mentioned(content: dict, body: str) -> bool: def is_mentioned(content: dict, body: str) -> bool:
if MENTION_RE.search(body or "") is not None: if MENTION_RE.search(body or "") is not None:
return True return True
if _body_mentions_token(body or ""):
return True
mentions = content.get("m.mentions", {}) mentions = content.get("m.mentions", {})
user_ids = mentions.get("user_ids", []) user_ids = mentions.get("user_ids", [])
if not isinstance(user_ids, list): if not isinstance(user_ids, list):