From 202ff97652e3a8082661dbeddeb31ea87ce47a52 Mon Sep 17 00:00:00 2001 From: A0000Xz <629995608@qq.com> Date: Tue, 1 Jul 2025 18:43:07 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E8=89=BE?= =?UTF-8?q?=E7=89=B9=E4=BF=A1=E6=81=AF=E7=9A=84=E5=AD=98=E5=82=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E4=BB=A5=E6=96=B9=E4=BE=BF=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/message_receive/storage.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chat/message_receive/storage.py b/src/chat/message_receive/storage.py index 9cd357ab2..4f79c6aac 100644 --- a/src/chat/message_receive/storage.py +++ b/src/chat/message_receive/storage.py @@ -49,6 +49,11 @@ class MessageStorage: # 安全地获取 user_info, 如果为 None 则视为空字典 (以防万一) user_info_from_chat = chat_info_dict.get("user_info") or {} + # 使用正则表达式匹配 @ 格式 + pattern_at = r'@<([^:>]+):\d+>' + # 替换为 @XXX 格式(对含艾特的消息进行处理,使其符合原本展示的文本形态,方便引用回复) + filtered_processed_plain_text = re.sub(pattern_at, r'@\1', filtered_processed_plain_text) + Messages.create( message_id=msg_id, time=float(message.message_info.time), From c87f36973f1680089e910922aaeeffb678d75ebf Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:30:05 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BC=98=E5=8C=96no=5Freply=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=92=8C=E5=8F=82=E6=95=B0=EF=BC=8C=E9=80=82=E9=85=8D?= =?UTF-8?q?=E7=A7=81=E8=81=8A=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8F=92=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E6=97=A0=E5=8F=8D=E5=BA=94=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/built_in/core_actions/no_reply.py | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/plugins/built_in/core_actions/no_reply.py b/src/plugins/built_in/core_actions/no_reply.py index 99337e515..f1c2b640b 100644 --- a/src/plugins/built_in/core_actions/no_reply.py +++ b/src/plugins/built_in/core_actions/no_reply.py @@ -1,5 +1,6 @@ import random import time +import asyncio from typing import Tuple # 导入新插件系统 @@ -15,6 +16,8 @@ from src.config.config import global_config logger = get_logger("core_actions") +#设置一个全局字典,确保同一个消息流的下一个NoReplyAction实例能够获取到上一次消息的时间戳 +_CHAT_START_TIMES = {} class NoReplyAction(BaseAction): """不回复动作,根据新消息的兴趣值或数量决定何时结束等待. @@ -39,29 +42,47 @@ class NoReplyAction(BaseAction): # 新增:兴趣值退出阈值 _interest_exit_threshold = 3.0 # 新增:消息数量退出阈值 - _min_exit_message_count = 5 - _max_exit_message_count = 10 + _min_exit_message_count = 4 + _max_exit_message_count = 8 # 动作参数定义 action_parameters = {"reason": "不回复的原因"} # 动作使用场景 - action_require = ["你发送了消息,目前无人回复"] + action_require = [ + "你发送了消息,目前无人回复", + "你觉得对方还没把话说完", + "你觉得当前话题不适合插嘴", + "你觉得自己说话太多了" + ] # 关联类型 associated_types = [] async def execute(self) -> Tuple[bool, str]: """执行不回复动作""" - import asyncio - try: + + # 获取或初始化当前消息的起始时间,因为用户消息是可能在刚决定好可用动作,但还没选择动作的时候发送的。原先的start_time设计会导致这种消息被漏掉,现在采用全局字典存储 + if self.chat_id not in _CHAT_START_TIMES: + # 如果对应消息流没有存储时间,就设置为当前时间 + _CHAT_START_TIMES[self.chat_id] = time.time() + start_time = _CHAT_START_TIMES[self.chat_id] + else: + message_current_time = time.time() + if message_current_time - _CHAT_START_TIMES[self.chat_id] > 600: + # 如果上一次NoReplyAction实例记录的最后消息时间戳距离现在时间戳超过了十分钟,将会把start_time设置为当前时间戳,避免在数据库内过度搜索 + start_time = message_current_time + logger.debug("距离上一次消息时间过长,已重置等待开始时间为当前时间") + else: + # 如果距离上一次noreply没有十分钟,就沿用上一次noreply退出时记录的最新消息时间戳 + start_time = _CHAT_START_TIMES[self.chat_id] + # 增加连续计数 NoReplyAction._consecutive_count += 1 count = NoReplyAction._consecutive_count reason = self.action_data.get("reason", "") - start_time = time.time() check_interval = 1.0 # 每秒检查一次 # 随机生成本次等待需要的新消息数量阈值 @@ -69,6 +90,9 @@ class NoReplyAction(BaseAction): logger.info( f"{self.log_prefix} 本次no_reply需要 {exit_message_count_threshold} 条新消息或累计兴趣值超过 {self._interest_exit_threshold} 才能打断" ) + if not self.is_group: + exit_message_count_threshold = 1 + logger.info(f"检测到当前环境为私聊,本次no_reply已更正为需要{exit_message_count_threshold}条新消息就能打断") logger.info(f"{self.log_prefix} 选择不回复(第{count}次),开始摸鱼,原因: {reason}") @@ -77,9 +101,9 @@ class NoReplyAction(BaseAction): current_time = time.time() elapsed_time = current_time - start_time - # 1. 检查新消息 + # 1. 检查新消息,默认过滤麦麦自己的消息 recent_messages_dict = message_api.get_messages_by_time_in_chat( - chat_id=self.chat_id, start_time=start_time, end_time=current_time + chat_id=self.chat_id, start_time=start_time, end_time=current_time, filter_mai=True ) new_message_count = len(recent_messages_dict) @@ -89,11 +113,20 @@ class NoReplyAction(BaseAction): f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{exit_message_count_threshold}),结束等待" ) exit_reason = f"{global_config.bot.nickname}(你)看到了{new_message_count}条新消息,可以考虑一下是否要进行回复" + # 如果是私聊,就稍微改一下退出理由 + if not self.is_group: + exit_reason = f"{global_config.bot.nickname}(你)看到了私聊的{new_message_count}条新消息,可以考虑一下是否要进行回复" await self.store_action_info( action_build_into_prompt=False, action_prompt_display=exit_reason, action_done=True, ) + + # 获取最后一条消息 + latest_message = recent_messages_dict[-1] + # 在退出时更新全局字典时间戳(加1微秒防止重复) + _CHAT_START_TIMES[self.chat_id] = latest_message['time'] + 0.000001 # 0.000001秒 = 1微秒 + return True, f"累计消息数量达到{new_message_count}条,结束等待 (等待时间: {elapsed_time:.1f}秒)" # 3. 检查累计兴趣值 @@ -115,6 +148,12 @@ class NoReplyAction(BaseAction): action_prompt_display=exit_reason, action_done=True, ) + + # 获取最后一条消息 + latest_message = recent_messages_dict[-1] + # 在退出时更新全局字典时间戳(加1微秒防止重复) + _CHAT_START_TIMES[self.chat_id] = latest_message['time'] + 0.000001 # 0.000001秒 = 1微秒 + return ( True, f"累计兴趣值达到{accumulated_interest:.2f},结束等待 (等待时间: {elapsed_time:.1f}秒)", From ef1ac55fe0a7071a1c362c5219005afcdb14d57f Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:31:07 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9filter=5F?= =?UTF-8?q?mai=E5=8F=82=E6=95=B0=E6=9D=A5=E5=86=B3=E5=AE=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E8=BF=87=E6=BB=A4=E9=BA=A6=E9=BA=A6=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin_system/apis/message_api.py | 50 +++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/plugin_system/apis/message_api.py b/src/plugin_system/apis/message_api.py index a4241ab53..d3e319595 100644 --- a/src/plugin_system/apis/message_api.py +++ b/src/plugin_system/apis/message_api.py @@ -9,6 +9,7 @@ """ from typing import List, Dict, Any, Tuple, Optional +from src.config.config import global_config import time from src.chat.utils.chat_message_builder import ( get_raw_msg_by_timestamp, @@ -34,7 +35,7 @@ from src.chat.utils.chat_message_builder import ( def get_messages_by_time( - start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest" + start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest", filter_mai: bool = False ) -> List[Dict[str, Any]]: """ 获取指定时间范围内的消息 @@ -44,15 +45,18 @@ def get_messages_by_time( end_time: 结束时间戳 limit: 限制返回的消息数量,0为不限制 limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_by_timestamp(start_time, end_time, limit, limit_mode)) return get_raw_msg_by_timestamp(start_time, end_time, limit, limit_mode) def get_messages_by_time_in_chat( - chat_id: str, start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest" + chat_id: str, start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest", filter_mai: bool = False ) -> List[Dict[str, Any]]: """ 获取指定聊天中指定时间范围内的消息 @@ -63,15 +67,18 @@ def get_messages_by_time_in_chat( end_time: 结束时间戳 limit: 限制返回的消息数量,0为不限制 limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode)) return get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode) def get_messages_by_time_in_chat_inclusive( - chat_id: str, start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest" + chat_id: str, start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest", filter_mai: bool = False ) -> List[Dict[str, Any]]: """ 获取指定聊天中指定时间范围内的消息(包含边界) @@ -82,10 +89,13 @@ def get_messages_by_time_in_chat_inclusive( end_time: 结束时间戳(包含) limit: 限制返回的消息数量,0为不限制 limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_by_timestamp_with_chat_inclusive(chat_id, start_time, end_time, limit, limit_mode)) return get_raw_msg_by_timestamp_with_chat_inclusive(chat_id, start_time, end_time, limit, limit_mode) @@ -115,7 +125,7 @@ def get_messages_by_time_in_chat_for_users( def get_random_chat_messages( - start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest" + start_time: float, end_time: float, limit: int = 0, limit_mode: str = "latest", filter_mai: bool = False ) -> List[Dict[str, Any]]: """ 随机选择一个聊天,返回该聊天在指定时间范围内的消息 @@ -125,10 +135,13 @@ def get_random_chat_messages( end_time: 结束时间戳 limit: 限制返回的消息数量,0为不限制 limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_by_timestamp_random(start_time, end_time, limit, limit_mode)) return get_raw_msg_by_timestamp_random(start_time, end_time, limit, limit_mode) @@ -151,21 +164,24 @@ def get_messages_by_time_for_users( return get_raw_msg_by_timestamp_with_users(start_time, end_time, person_ids, limit, limit_mode) -def get_messages_before_time(timestamp: float, limit: int = 0) -> List[Dict[str, Any]]: +def get_messages_before_time(timestamp: float, limit: int = 0, filter_mai: bool = False) -> List[Dict[str, Any]]: """ 获取指定时间戳之前的消息 Args: timestamp: 时间戳 limit: 限制返回的消息数量,0为不限制 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_before_timestamp(timestamp, limit)) return get_raw_msg_before_timestamp(timestamp, limit) -def get_messages_before_time_in_chat(chat_id: str, timestamp: float, limit: int = 0) -> List[Dict[str, Any]]: +def get_messages_before_time_in_chat(chat_id: str, timestamp: float, limit: int = 0, filter_mai: bool = False) -> List[Dict[str, Any]]: """ 获取指定聊天中指定时间戳之前的消息 @@ -173,10 +189,13 @@ def get_messages_before_time_in_chat(chat_id: str, timestamp: float, limit: int chat_id: 聊天ID timestamp: 时间戳 limit: 限制返回的消息数量,0为不限制 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ + if filter_mai: + return filter_mai_messages(get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit)) return get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit) @@ -196,7 +215,7 @@ def get_messages_before_time_for_users(timestamp: float, person_ids: list, limit def get_recent_messages( - chat_id: str, hours: float = 24.0, limit: int = 100, limit_mode: str = "latest" + chat_id: str, hours: float = 24.0, limit: int = 100, limit_mode: str = "latest", filter_mai: bool = False ) -> List[Dict[str, Any]]: """ 获取指定聊天中最近一段时间的消息 @@ -206,12 +225,15 @@ def get_recent_messages( hours: 最近多少小时,默认24小时 limit: 限制返回的消息数量,默认100条 limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录 + filter_mai: 是否过滤麦麦自身的消息,默认为False Returns: 消息列表 """ now = time.time() start_time = now - hours * 3600 + if filter_mai: + return filter_mai_messages(get_raw_msg_by_timestamp_with_chat(chat_id, start_time, now, limit, limit_mode)) return get_raw_msg_by_timestamp_with_chat(chat_id, start_time, now, limit, limit_mode) @@ -319,3 +341,17 @@ async def get_person_ids_from_messages(messages: List[Dict[str, Any]]) -> List[s 用户ID列表 """ return await get_person_id_list(messages) + +# ============================================================================= +# 消息过滤函数 +# ============================================================================= + +def filter_mai_messages(messages: List[Dict[str, Any]]) -> List[Dict[str, Any]]: + """ + 从消息列表中移除麦麦的消息 + Args: + messages: 消息列表,每个元素是消息字典 + Returns: + 过滤后的消息列表 + """ + return [msg for msg in messages if msg.get("user_id") != str(global_config.bot.qq_account)] From 9dfc15e61c22270267c2cfb5dab812c65e20b538 Mon Sep 17 00:00:00 2001 From: A0000Xz <122650088+A0000Xz@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:32:18 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E7=A7=81=E8=81=8A=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E9=80=80=E5=87=BAfocus=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8Dfocus=E9=80=80=E5=87=BA=E9=98=88?= =?UTF-8?q?=E5=80=BC=E5=8F=8D=E5=90=91=E8=AE=A1=E7=AE=97=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/focus_chat/heartFC_chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index 08008bfe9..30c0dbb20 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -459,7 +459,7 @@ class HeartFChatting: logger.debug(f"{self.log_prefix} 从action_data中获取系统命令: {command}") # 新增:消息计数和疲惫检查 - if action == "reply" and success: + if action == "reply" and success and self.chat_stream.context.message.message_info.group_info: self._message_count += 1 current_threshold = self._get_current_fatigue_threshold() logger.info( @@ -501,7 +501,7 @@ class HeartFChatting: Returns: int: 当前的疲惫阈值 """ - return max(10, int(30 / global_config.chat.exit_focus_threshold)) + return max(10, int(30 * global_config.chat.exit_focus_threshold)) def get_message_count_info(self) -> dict: """获取消息计数信息 From b1f50628ad71b71c5be074e9746b1750b6c398c4 Mon Sep 17 00:00:00 2001 From: A0000Xz <629995608@qq.com> Date: Fri, 11 Jul 2025 21:54:31 +0800 Subject: [PATCH 5/7] =?UTF-8?q?Revert=20"=E4=BC=98=E5=8C=96no=5Freply?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=92=8C=E5=8F=82=E6=95=B0=EF=BC=8C=E9=80=82?= =?UTF-8?q?=E9=85=8D=E7=A7=81=E8=81=8A=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8F=92?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E6=B6=88=E6=81=AF=E6=97=A0=E5=8F=8D=E5=BA=94?= =?UTF-8?q?=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c87f36973f1680089e910922aaeeffb678d75ebf. --- src/plugins/built_in/core_actions/no_reply.py | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/src/plugins/built_in/core_actions/no_reply.py b/src/plugins/built_in/core_actions/no_reply.py index f1c2b640b..99337e515 100644 --- a/src/plugins/built_in/core_actions/no_reply.py +++ b/src/plugins/built_in/core_actions/no_reply.py @@ -1,6 +1,5 @@ import random import time -import asyncio from typing import Tuple # 导入新插件系统 @@ -16,8 +15,6 @@ from src.config.config import global_config logger = get_logger("core_actions") -#设置一个全局字典,确保同一个消息流的下一个NoReplyAction实例能够获取到上一次消息的时间戳 -_CHAT_START_TIMES = {} class NoReplyAction(BaseAction): """不回复动作,根据新消息的兴趣值或数量决定何时结束等待. @@ -42,47 +39,29 @@ class NoReplyAction(BaseAction): # 新增:兴趣值退出阈值 _interest_exit_threshold = 3.0 # 新增:消息数量退出阈值 - _min_exit_message_count = 4 - _max_exit_message_count = 8 + _min_exit_message_count = 5 + _max_exit_message_count = 10 # 动作参数定义 action_parameters = {"reason": "不回复的原因"} # 动作使用场景 - action_require = [ - "你发送了消息,目前无人回复", - "你觉得对方还没把话说完", - "你觉得当前话题不适合插嘴", - "你觉得自己说话太多了" - ] + action_require = ["你发送了消息,目前无人回复"] # 关联类型 associated_types = [] async def execute(self) -> Tuple[bool, str]: """执行不回复动作""" + import asyncio + try: - - # 获取或初始化当前消息的起始时间,因为用户消息是可能在刚决定好可用动作,但还没选择动作的时候发送的。原先的start_time设计会导致这种消息被漏掉,现在采用全局字典存储 - if self.chat_id not in _CHAT_START_TIMES: - # 如果对应消息流没有存储时间,就设置为当前时间 - _CHAT_START_TIMES[self.chat_id] = time.time() - start_time = _CHAT_START_TIMES[self.chat_id] - else: - message_current_time = time.time() - if message_current_time - _CHAT_START_TIMES[self.chat_id] > 600: - # 如果上一次NoReplyAction实例记录的最后消息时间戳距离现在时间戳超过了十分钟,将会把start_time设置为当前时间戳,避免在数据库内过度搜索 - start_time = message_current_time - logger.debug("距离上一次消息时间过长,已重置等待开始时间为当前时间") - else: - # 如果距离上一次noreply没有十分钟,就沿用上一次noreply退出时记录的最新消息时间戳 - start_time = _CHAT_START_TIMES[self.chat_id] - # 增加连续计数 NoReplyAction._consecutive_count += 1 count = NoReplyAction._consecutive_count reason = self.action_data.get("reason", "") + start_time = time.time() check_interval = 1.0 # 每秒检查一次 # 随机生成本次等待需要的新消息数量阈值 @@ -90,9 +69,6 @@ class NoReplyAction(BaseAction): logger.info( f"{self.log_prefix} 本次no_reply需要 {exit_message_count_threshold} 条新消息或累计兴趣值超过 {self._interest_exit_threshold} 才能打断" ) - if not self.is_group: - exit_message_count_threshold = 1 - logger.info(f"检测到当前环境为私聊,本次no_reply已更正为需要{exit_message_count_threshold}条新消息就能打断") logger.info(f"{self.log_prefix} 选择不回复(第{count}次),开始摸鱼,原因: {reason}") @@ -101,9 +77,9 @@ class NoReplyAction(BaseAction): current_time = time.time() elapsed_time = current_time - start_time - # 1. 检查新消息,默认过滤麦麦自己的消息 + # 1. 检查新消息 recent_messages_dict = message_api.get_messages_by_time_in_chat( - chat_id=self.chat_id, start_time=start_time, end_time=current_time, filter_mai=True + chat_id=self.chat_id, start_time=start_time, end_time=current_time ) new_message_count = len(recent_messages_dict) @@ -113,20 +89,11 @@ class NoReplyAction(BaseAction): f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{exit_message_count_threshold}),结束等待" ) exit_reason = f"{global_config.bot.nickname}(你)看到了{new_message_count}条新消息,可以考虑一下是否要进行回复" - # 如果是私聊,就稍微改一下退出理由 - if not self.is_group: - exit_reason = f"{global_config.bot.nickname}(你)看到了私聊的{new_message_count}条新消息,可以考虑一下是否要进行回复" await self.store_action_info( action_build_into_prompt=False, action_prompt_display=exit_reason, action_done=True, ) - - # 获取最后一条消息 - latest_message = recent_messages_dict[-1] - # 在退出时更新全局字典时间戳(加1微秒防止重复) - _CHAT_START_TIMES[self.chat_id] = latest_message['time'] + 0.000001 # 0.000001秒 = 1微秒 - return True, f"累计消息数量达到{new_message_count}条,结束等待 (等待时间: {elapsed_time:.1f}秒)" # 3. 检查累计兴趣值 @@ -148,12 +115,6 @@ class NoReplyAction(BaseAction): action_prompt_display=exit_reason, action_done=True, ) - - # 获取最后一条消息 - latest_message = recent_messages_dict[-1] - # 在退出时更新全局字典时间戳(加1微秒防止重复) - _CHAT_START_TIMES[self.chat_id] = latest_message['time'] + 0.000001 # 0.000001秒 = 1微秒 - return ( True, f"累计兴趣值达到{accumulated_interest:.2f},结束等待 (等待时间: {elapsed_time:.1f}秒)", From 8daab59ec818cedd6f4c7ebb78c75664d7ff1744 Mon Sep 17 00:00:00 2001 From: A0000Xz <629995608@qq.com> Date: Fri, 11 Jul 2025 21:58:38 +0800 Subject: [PATCH 6/7] =?UTF-8?q?Revert=20"=E7=A7=81=E8=81=8A=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=8F=AF=E8=83=BD=E9=80=80=E5=87=BAfocus=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E4=BF=AE=E5=A4=8Dfocus=E9=80=80=E5=87=BA?= =?UTF-8?q?=E9=98=88=E5=80=BC=E5=8F=8D=E5=90=91=E8=AE=A1=E7=AE=97=E7=9A=84?= =?UTF-8?q?BUG"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9dfc15e61c22270267c2cfb5dab812c65e20b538. --- src/chat/focus_chat/heartFC_chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index 30c0dbb20..08008bfe9 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -459,7 +459,7 @@ class HeartFChatting: logger.debug(f"{self.log_prefix} 从action_data中获取系统命令: {command}") # 新增:消息计数和疲惫检查 - if action == "reply" and success and self.chat_stream.context.message.message_info.group_info: + if action == "reply" and success: self._message_count += 1 current_threshold = self._get_current_fatigue_threshold() logger.info( @@ -501,7 +501,7 @@ class HeartFChatting: Returns: int: 当前的疲惫阈值 """ - return max(10, int(30 * global_config.chat.exit_focus_threshold)) + return max(10, int(30 / global_config.chat.exit_focus_threshold)) def get_message_count_info(self) -> dict: """获取消息计数信息 From ce1215158cb277043bc7b2a1735f5722c869a1b8 Mon Sep 17 00:00:00 2001 From: A0000Xz <629995608@qq.com> Date: Fri, 11 Jul 2025 22:01:46 +0800 Subject: [PATCH 7/7] Update storage.py --- src/chat/message_receive/storage.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/chat/message_receive/storage.py b/src/chat/message_receive/storage.py index 456b93df9..998e06f21 100644 --- a/src/chat/message_receive/storage.py +++ b/src/chat/message_receive/storage.py @@ -55,11 +55,6 @@ class MessageStorage: # 安全地获取 user_info, 如果为 None 则视为空字典 (以防万一) user_info_from_chat = chat_info_dict.get("user_info") or {} - # 使用正则表达式匹配 @ 格式 - pattern_at = r'@<([^:>]+):\d+>' - # 替换为 @XXX 格式(对含艾特的消息进行处理,使其符合原本展示的文本形态,方便引用回复) - filtered_processed_plain_text = re.sub(pattern_at, r'@\1', filtered_processed_plain_text) - Messages.create( message_id=msg_id, time=float(message.message_info.time),