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) await self._send_text(room.room_id, HELP_TEXT)
return return
# Check if bot is mentioned (display name or user ID) # In DMs (2 members), respond to all messages; in groups, require @mention
bot_display = self.client.user_id.split(":")[0].lstrip("@") is_dm = room.member_count == 2
mentioned = ( if not is_dm:
BOT_USER in body bot_display = self.client.user_id.split(":")[0].lstrip("@")
or f"@{bot_display}" in body.lower() mentioned = (
or bot_display.lower() in body.lower() BOT_USER in body
) or f"@{bot_display}" in body.lower()
if not mentioned: or bot_display.lower() in body.lower()
return )
if not mentioned:
return
if not self.llm: if not self.llm:
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).") 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): async def on_megolm(self, room, event: MegolmEvent):
"""Log undecryptable messages.""" """Request keys for undecryptable messages."""
logger.warning( 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, 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): async def on_key_verification(self, event):
"""Auto-accept key verification requests.""" """Auto-accept key verification requests."""