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.
This commit is contained in:
parent
2d564afd97
commit
c47f947f80
1 changed files with 10 additions and 7 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue