From 265d946ebdb3b94110489a05f0405921a6c2f98d Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Wed, 26 Nov 2025 16:09:44 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=AD=A3=E7=A1=AE=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/brain_chat/brain_chat.py | 3 ++- src/chat/heart_flow/heartFC_chat.py | 3 ++- src/chat/message_receive/bot.py | 1 + src/chat/message_receive/message.py | 1 + src/chat/message_receive/storage.py | 3 +++ src/chat/utils/chat_message_builder.py | 12 +++++++++- src/common/data_models/database_data_model.py | 3 +++ src/common/database/database_model.py | 1 + src/common/message_repository.py | 4 ++++ src/plugin_system/apis/message_api.py | 23 ++++++++++++------- 10 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/chat/brain_chat/brain_chat.py b/src/chat/brain_chat/brain_chat.py index 29840ff1..c1b09fb7 100644 --- a/src/chat/brain_chat/brain_chat.py +++ b/src/chat/brain_chat/brain_chat.py @@ -164,7 +164,8 @@ class BrainChatting: limit=20, limit_mode="latest", filter_mai=True, - filter_command=True, + filter_command=False, + filter_no_read_command=True, ) if len(recent_messages_list) >= 1: diff --git a/src/chat/heart_flow/heartFC_chat.py b/src/chat/heart_flow/heartFC_chat.py index b95ec584..4e28eae2 100644 --- a/src/chat/heart_flow/heartFC_chat.py +++ b/src/chat/heart_flow/heartFC_chat.py @@ -189,7 +189,8 @@ class HeartFChatting: limit=20, limit_mode="latest", filter_mai=True, - filter_command=True, + filter_command=False, + filter_no_read_command=True, ) # 根据连续 no_reply 次数动态调整阈值 diff --git a/src/chat/message_receive/bot.py b/src/chat/message_receive/bot.py index 070f78bd..2d798f54 100644 --- a/src/chat/message_receive/bot.py +++ b/src/chat/message_receive/bot.py @@ -116,6 +116,7 @@ class ChatBot: try: # 执行命令 success, response, intercept_message = await command_instance.execute() + message.is_no_read_command = bool(intercept_message) # 记录命令执行结果 if success: diff --git a/src/chat/message_receive/message.py b/src/chat/message_receive/message.py index 6c1ec1a7..9528785e 100644 --- a/src/chat/message_receive/message.py +++ b/src/chat/message_receive/message.py @@ -122,6 +122,7 @@ class MessageRecv(Message): self.is_notify = False self.is_command = False + self.is_no_read_command = False self.priority_mode = "interest" self.priority_info = None diff --git a/src/chat/message_receive/storage.py b/src/chat/message_receive/storage.py index 2abf4ce2..8d85d166 100644 --- a/src/chat/message_receive/storage.py +++ b/src/chat/message_receive/storage.py @@ -67,6 +67,7 @@ class MessageStorage: key_words = "" key_words_lite = "" selected_expressions = message.selected_expressions + is_no_read_command = False else: filtered_display_message = "" interest_value = message.interest_value @@ -80,6 +81,7 @@ class MessageStorage: is_picid = message.is_picid is_notify = message.is_notify is_command = message.is_command + is_no_read_command = getattr(message, "is_no_read_command", False) # 序列化关键词列表为JSON字符串 key_words = MessageStorage._serialize_keywords(message.key_words) key_words_lite = MessageStorage._serialize_keywords(message.key_words_lite) @@ -131,6 +133,7 @@ class MessageStorage: is_picid=is_picid, is_notify=is_notify, is_command=is_command, + is_no_read_command=is_no_read_command, key_words=key_words, key_words_lite=key_words_lite, selected_expressions=selected_expressions, diff --git a/src/chat/utils/chat_message_builder.py b/src/chat/utils/chat_message_builder.py index 30db7584..2938fff1 100644 --- a/src/chat/utils/chat_message_builder.py +++ b/src/chat/utils/chat_message_builder.py @@ -120,6 +120,7 @@ def get_raw_msg_by_timestamp_with_chat( limit_mode: str = "latest", filter_bot=False, filter_command=False, + filter_no_read_command=False, ) -> List[DatabaseMessages]: """获取在特定聊天从指定时间戳到指定时间戳的消息,按时间升序排序,返回消息列表 limit: 限制返回的消息数量,0为不限制 @@ -137,6 +138,7 @@ def get_raw_msg_by_timestamp_with_chat( limit_mode=limit_mode, filter_bot=filter_bot, filter_command=filter_command, + filter_no_read_command=filter_no_read_command, ) @@ -147,6 +149,8 @@ def get_raw_msg_by_timestamp_with_chat_inclusive( limit: int = 0, limit_mode: str = "latest", filter_bot=False, + filter_command=False, + filter_no_read_command=False, ) -> List[DatabaseMessages]: """获取在特定聊天从指定时间戳到指定时间戳的消息(包含边界),按时间升序排序,返回消息列表 limit: 限制返回的消息数量,0为不限制 @@ -157,7 +161,13 @@ def get_raw_msg_by_timestamp_with_chat_inclusive( sort_order = [("time", 1)] if limit == 0 else None # 直接将 limit_mode 传递给 find_messages return find_messages( - message_filter=filter_query, sort=sort_order, limit=limit, limit_mode=limit_mode, filter_bot=filter_bot + message_filter=filter_query, + sort=sort_order, + limit=limit, + limit_mode=limit_mode, + filter_bot=filter_bot, + filter_command=filter_command, + filter_no_read_command=filter_no_read_command, ) diff --git a/src/common/data_models/database_data_model.py b/src/common/data_models/database_data_model.py index b981bd33..9707add8 100644 --- a/src/common/data_models/database_data_model.py +++ b/src/common/data_models/database_data_model.py @@ -77,6 +77,7 @@ class DatabaseMessages(BaseDataModel): is_emoji: bool = False, is_picid: bool = False, is_command: bool = False, + is_no_read_command: bool = False, is_notify: bool = False, selected_expressions: Optional[str] = None, user_id: str = "", @@ -119,6 +120,7 @@ class DatabaseMessages(BaseDataModel): self.is_emoji = is_emoji self.is_picid = is_picid self.is_command = is_command + self.is_no_read_command = is_no_read_command self.is_notify = is_notify self.selected_expressions = selected_expressions @@ -186,6 +188,7 @@ class DatabaseMessages(BaseDataModel): "is_emoji": self.is_emoji, "is_picid": self.is_picid, "is_command": self.is_command, + "is_no_read_command": self.is_no_read_command, "is_notify": self.is_notify, "selected_expressions": self.selected_expressions, "user_id": self.user_info.user_id, diff --git a/src/common/database/database_model.py b/src/common/database/database_model.py index 40d542eb..bfb11d5a 100644 --- a/src/common/database/database_model.py +++ b/src/common/database/database_model.py @@ -170,6 +170,7 @@ class Messages(BaseModel): is_emoji = BooleanField(default=False) is_picid = BooleanField(default=False) is_command = BooleanField(default=False) + is_no_read_command = BooleanField(default=False) is_notify = BooleanField(default=False) selected_expressions = TextField(null=True) diff --git a/src/common/message_repository.py b/src/common/message_repository.py index fb9120ac..4b9c6b35 100644 --- a/src/common/message_repository.py +++ b/src/common/message_repository.py @@ -25,6 +25,7 @@ def find_messages( limit_mode: str = "latest", filter_bot=False, filter_command=False, + filter_no_read_command=False, ) -> List[DatabaseMessages]: """ 根据提供的过滤器、排序和限制条件查找消息。 @@ -84,6 +85,9 @@ def find_messages( # 使用按位取反构造 Peewee 的 NOT 条件,避免直接与 False 比较 query = query.where(~Messages.is_command) + if filter_no_read_command: + query = query.where(~Messages.is_no_read_command) + if limit > 0: if limit_mode == "earliest": # 获取时间最早的 limit 条记录,已经是正序 diff --git a/src/plugin_system/apis/message_api.py b/src/plugin_system/apis/message_api.py index cfacd558..4fb65ccb 100644 --- a/src/plugin_system/apis/message_api.py +++ b/src/plugin_system/apis/message_api.py @@ -72,6 +72,7 @@ def get_messages_by_time_in_chat( limit_mode: str = "latest", filter_mai: bool = False, filter_command: bool = False, + filter_no_read_command: bool = False, ) -> List[DatabaseMessages]: """ 获取指定聊天中指定时间范围内的消息 @@ -110,6 +111,7 @@ def get_messages_by_time_in_chat( limit_mode=limit_mode, filter_bot=filter_mai, filter_command=filter_command, + filter_no_read_command=filter_no_read_command, ) @@ -121,6 +123,7 @@ def get_messages_by_time_in_chat_inclusive( limit_mode: str = "latest", filter_mai: bool = False, filter_command: bool = False, + filter_no_read_command: bool = False, ) -> List[DatabaseMessages]: """ 获取指定聊天中指定时间范围内的消息(包含边界) @@ -147,15 +150,19 @@ def get_messages_by_time_in_chat_inclusive( raise ValueError("chat_id 不能为空") if not isinstance(chat_id, str): raise ValueError("chat_id 必须是字符串类型") - if filter_mai: - return filter_mai_messages( - get_raw_msg_by_timestamp_with_chat_inclusive( - chat_id, start_time, end_time, limit, limit_mode, filter_command - ) - ) - return get_raw_msg_by_timestamp_with_chat_inclusive( - chat_id, start_time, end_time, limit, limit_mode, filter_command + messages = get_raw_msg_by_timestamp_with_chat_inclusive( + chat_id=chat_id, + timestamp_start=start_time, + timestamp_end=end_time, + limit=limit, + limit_mode=limit_mode, + filter_bot=filter_mai, + filter_command=filter_command, + filter_no_read_command=filter_no_read_command, ) + if filter_mai: + return filter_mai_messages(messages) + return messages def get_messages_by_time_in_chat_for_users(