Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dev2/agents/qc-agent-responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from pathlib import Path

AGENTS = ("cha0spunk", "coinpay", "knox", "nora", "quill", "riotcoder", "rootkey")
AGENT_HANDLE_ALIASES = {"rootkey": ("rootkey_agent",)}
AGENT_HANDLES = frozenset((*AGENTS, *(handle for aliases in AGENT_HANDLE_ALIASES.values() for handle in aliases)))
OPERATOR_ID = "4826dea7-225a-45df-a56f-6f380bd74ecf"
HOME = Path.home()
AGENT = os.environ.get("QC_AGENT", "")
Expand Down Expand Up @@ -107,7 +109,10 @@ def mentioned_handles(text):
low = (text or "").lower()
if "all seven" in low or "all six" in low or "all agents" in low or "everyone" in low:
return list(AGENTS)
return [name for name in AGENTS if re.search(rf"(?<![a-z0-9_])@?{re.escape(name)}(?![a-z0-9_])", low)]
return [
name for name in AGENTS
if any(re.search(rf"(?<![a-z0-9_])@?{re.escape(handle)}(?![a-z0-9_])", low) for handle in (name, *AGENT_HANDLE_ALIASES.get(name, ())))
]


def route(text, message_id):
Expand Down Expand Up @@ -247,7 +252,7 @@ def handle(message, env):
return
targets = [AGENT]
else:
if sender in AGENTS:
if sender in AGENT_HANDLES:
targets = mentioned_handles(text)
if AGENT not in targets:
return
Expand Down
Loading