Browse Source

Refine message filtering in bot event processing

Enhanced event processing in the bot's message retrieval logic to
improve message relevance and accuracy. Changes include accepting all
'gptbot' prefixed events, refining handling of 'ignoreolder' command
with exact match rather than starts with, and now passing through
'custom' commands that start with '!'. The default behavior now excludes
notices unless explicitly included. This update allows for more precise
command interactions and reduces clutter from irrelevant notices.
Kumi 9 months ago
parent
commit
c47f947f80
1 changed files with 10 additions and 7 deletions
  1. 10 7
      src/gptbot/classes/bot.py

+ 10 - 7
src/gptbot/classes/bot.py

@@ -296,7 +296,7 @@ class GPTBot:
         self,
         self,
         room: str | MatrixRoom,
         room: str | MatrixRoom,
         n: Optional[int],
         n: Optional[int],
-        ignore_bot_commands: bool = False,
+        ignore_notices: bool = True,
     ):
     ):
         messages = []
         messages = []
         n = n or self.max_messages
         n = n or self.max_messages
@@ -323,17 +323,20 @@ class GPTBot:
             if len(messages) >= n:
             if len(messages) >= n:
                 break
                 break
 
 
-            if isinstance(event, RoomMessageText):
-                if event.body.startswith("!gptbot ignoreolder"):
+            if event.type.startswith("gptbot"):
+                messages.append(event)
+
+            elif isinstance(event, RoomMessageText):
+                if event.body.split() == ["!gptbot", "ignoreolder"]:
                     break
                     break
-                if (not event.body.startswith("!")) or (not ignore_bot_commands):
+                if (not event.body.startswith("!")) or (event.body.split()[1] == "custom"):
                     messages.append(event)
                     messages.append(event)
 
 
-            if isinstance(event, RoomMessageNotice):
-                if not ignore_bot_commands:
+            elif isinstance(event, RoomMessageNotice):
+                if not ignore_notices:
                     messages.append(event)
                     messages.append(event)
 
 
-            if isinstance(event, RoomMessageMedia):
+            elif isinstance(event, RoomMessageMedia):
                 messages.append(event)
                 messages.append(event)
 
 
         self.logger.log(f"Found {len(messages)} messages (limit: {n})", "debug")
         self.logger.log(f"Found {len(messages)} messages (limit: {n})", "debug")