From c47f947f80f79a443bbd622833662e3122b121ef Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 18 Feb 2024 10:49:27 +0100 Subject: [PATCH] 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. --- src/gptbot/classes/bot.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/gptbot/classes/bot.py b/src/gptbot/classes/bot.py index 3361b77..46a938f 100644 --- a/src/gptbot/classes/bot.py +++ b/src/gptbot/classes/bot.py @@ -296,7 +296,7 @@ class GPTBot: self, room: str | MatrixRoom, n: Optional[int], - ignore_bot_commands: bool = False, + ignore_notices: bool = True, ): messages = [] n = n or self.max_messages @@ -323,17 +323,20 @@ class GPTBot: if len(messages) >= n: 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 - if (not event.body.startswith("!")) or (not ignore_bot_commands): + if (not event.body.startswith("!")) or (event.body.split()[1] == "custom"): messages.append(event) - if isinstance(event, RoomMessageNotice): - if not ignore_bot_commands: + elif isinstance(event, RoomMessageNotice): + if not ignore_notices: messages.append(event) - if isinstance(event, RoomMessageMedia): + elif isinstance(event, RoomMessageMedia): messages.append(event) self.logger.log(f"Found {len(messages)} messages (limit: {n})", "debug")