feat: respond to all messages in DMs without requiring @mention

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-02-15 19:02:36 +02:00
parent 07dfc05f76
commit ac26c71709

28
bot.py
View File

@@ -279,15 +279,17 @@ class Bot:
await self._send_text(room.room_id, HELP_TEXT)
return
# Check if bot is mentioned (display name or user ID)
bot_display = self.client.user_id.split(":")[0].lstrip("@")
mentioned = (
BOT_USER in body
or f"@{bot_display}" in body.lower()
or bot_display.lower() in body.lower()
)
if not mentioned:
return
# In DMs (2 members), respond to all messages; in groups, require @mention
is_dm = room.member_count == 2
if not is_dm:
bot_display = self.client.user_id.split(":")[0].lstrip("@")
mentioned = (
BOT_USER in body
or f"@{bot_display}" in body.lower()
or bot_display.lower() in body.lower()
)
if not mentioned:
return
if not self.llm:
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).")
@@ -405,11 +407,15 @@ class Bot:
)
async def on_megolm(self, room, event: MegolmEvent):
"""Log undecryptable messages."""
"""Request keys for undecryptable messages."""
logger.warning(
"Undecryptable event %s in %s from %s",
"Undecryptable event %s in %s from %s — requesting keys",
event.event_id, room.room_id, event.sender,
)
try:
await self.client.request_room_key(event)
except Exception:
logger.debug("Key request failed", exc_info=True)
async def on_key_verification(self, event):
"""Auto-accept key verification requests."""