From ac26c717096b7f54504468d9f5c1e32203715f9b Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Sun, 15 Feb 2026 19:02:36 +0200 Subject: [PATCH] feat: respond to all messages in DMs without requiring @mention Co-Authored-By: Claude Opus 4.6 --- bot.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index 20ab2a0..2b29627 100644 --- a/bot.py +++ b/bot.py @@ -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."""