From e2ce6a14f435e5cfd8c37f6afcf9baaec1f1db06 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Wed, 16 Jul 2025 12:06:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E7=B3=BB?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86reply?= =?UTF-8?q?=E2=80=94=E2=80=94to=EF=BC=8C=E4=BC=98=E5=8C=96s4u=E7=9A=84prom?= =?UTF-8?q?pt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/focus_chat/heartFC_chat.py | 33 +++++++++++-------- src/plugin_system/apis/plugin_register_api.py | 2 -- src/plugin_system/apis/send_api.py | 5 ++- src/plugin_system/base/base_action.py | 10 ++++-- src/plugins/built_in/core_actions/plugin.py | 7 ++-- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index ec3724ad5..e36823e9e 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -115,7 +115,7 @@ class HeartFChatting: logger.info(f"{self.log_prefix} HeartFChatting 初始化完成") - self.energy_value = 1 + self.energy_value = 5 async def start(self): """检查是否需要启动主循环,如果未激活则启动。""" @@ -176,11 +176,11 @@ class HeartFChatting: async def _energy_loop(self): while self.running: - await asyncio.sleep(1) + await asyncio.sleep(10) if self.loop_mode == ChatMode.NORMAL: - self.energy_value -= 1 - if self.energy_value <= 0: - self.energy_value = 0 + self.energy_value -= 0.3 + if self.energy_value <= 0.3: + self.energy_value = 0.3 def print_cycle_info(self, cycle_timers): # 记录循环信息和计时器结果 @@ -202,8 +202,8 @@ class HeartFChatting: self.energy_value -= 1 * global_config.chat.focus_value else: self.energy_value -= 3 * global_config.chat.focus_value - if self.energy_value <= 0: - self.energy_value = 0 + if self.energy_value <= 1: + self.energy_value = 1 self.loop_mode = ChatMode.NORMAL return True @@ -233,7 +233,11 @@ class HeartFChatting: if_think = await self.normal_response(earliest_messages_data) if if_think: - self.energy_value *= 1.1 / (global_config.chat.focus_value + 0.2) + if global_config.chat.focus_value <0.1: + factor = 0.1 + else: + factor = global_config.chat.focus_value + self.energy_value *= 1.1 / factor logger.info(f"{self.log_prefix} 麦麦进行了思考,能量值增加1,当前能量值:{self.energy_value}") return True @@ -325,7 +329,7 @@ class HeartFChatting: logger.info(f"[{self.log_prefix}] {global_config.bot.nickname} 决定的回复内容: {content}") # 发送回复 (不再需要传入 chat) - await self._send_response(response_set, reply_to_str, loop_start_time) + await self._send_response(response_set, reply_to_str, loop_start_time,message_data) return True @@ -526,11 +530,14 @@ class HeartFChatting: logger.error(f"[{self.log_prefix}] 回复生成出现错误:{str(e)} {traceback.format_exc()}") return None - async def _send_response(self, reply_set, reply_to, thinking_start_time): + async def _send_response(self, reply_set, reply_to, thinking_start_time,message_data): current_time = time.time() new_message_count = message_api.count_new_messages( chat_id=self.chat_stream.stream_id, start_time=thinking_start_time, end_time=current_time ) + platform = message_data.get("platform", "") + user_id = message_data.get("user_id", "") + reply_to_platform_id = f"{platform}:{user_id}" need_reply = new_message_count >= random.randint(2, 4) @@ -545,13 +552,13 @@ class HeartFChatting: if not first_replied: if need_reply: await send_api.text_to_stream( - text=data, stream_id=self.chat_stream.stream_id, reply_to=reply_to, typing=False + text=data, stream_id=self.chat_stream.stream_id, reply_to=reply_to, reply_to_platform_id=reply_to_platform_id, typing=False ) else: - await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, typing=False) + await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, reply_to_platform_id=reply_to_platform_id, typing=False) first_replied = True else: - await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, typing=True) + await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, reply_to_platform_id=reply_to_platform_id, typing=True) reply_text += data return reply_text diff --git a/src/plugin_system/apis/plugin_register_api.py b/src/plugin_system/apis/plugin_register_api.py index 8291a314f..b3cc58450 100644 --- a/src/plugin_system/apis/plugin_register_api.py +++ b/src/plugin_system/apis/plugin_register_api.py @@ -29,8 +29,6 @@ def register_plugin(cls): return cls def register_event_plugin(cls, *args, **kwargs): - from src.plugin_system.core.events_manager import events_manager - from src.plugin_system.base.component_types import EventType """事件插件注册装饰器 diff --git a/src/plugin_system/apis/send_api.py b/src/plugin_system/apis/send_api.py index 91e3266d5..97bee9908 100644 --- a/src/plugin_system/apis/send_api.py +++ b/src/plugin_system/apis/send_api.py @@ -50,6 +50,7 @@ async def _send_to_target( display_message: str = "", typing: bool = False, reply_to: str = "", + reply_to_platform_id: str = "", storage_message: bool = True, show_log: bool = True, ) -> bool: @@ -110,6 +111,7 @@ async def _send_to_target( is_head=True, is_emoji=(message_type == "emoji"), thinking_start_time=current_time, + reply_to = reply_to_platform_id ) # 发送消息 @@ -279,6 +281,7 @@ async def text_to_stream( stream_id: str, typing: bool = False, reply_to: str = "", + reply_to_platform_id: str = "", storage_message: bool = True, ) -> bool: """向指定流发送文本消息 @@ -293,7 +296,7 @@ async def text_to_stream( Returns: bool: 是否发送成功 """ - return await _send_to_target("text", text, stream_id, "", typing, reply_to, storage_message) + return await _send_to_target("text", text, stream_id, "", typing, reply_to, reply_to_platform_id, storage_message) async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bool = True) -> bool: diff --git a/src/plugin_system/base/base_action.py b/src/plugin_system/base/base_action.py index 26bf9ad3f..2c559a2c7 100644 --- a/src/plugin_system/base/base_action.py +++ b/src/plugin_system/base/base_action.py @@ -199,7 +199,7 @@ class BaseAction(ABC): logger.error(f"{self.log_prefix} 等待新消息时发生错误: {e}") return False, f"等待新消息失败: {str(e)}" - async def send_text(self, content: str, reply_to: str = "", typing: bool = False) -> bool: + async def send_text(self, content: str, reply_to: str = "", reply_to_platform_id: str = "", typing: bool = False) -> bool: """发送文本消息 Args: @@ -213,7 +213,13 @@ class BaseAction(ABC): logger.error(f"{self.log_prefix} 缺少聊天ID") return False - return await send_api.text_to_stream(text=content, stream_id=self.chat_id, reply_to=reply_to, typing=typing) + return await send_api.text_to_stream( + text=content, + stream_id=self.chat_id, + reply_to=reply_to, + reply_to_platform_id=reply_to_platform_id, + typing=typing, + ) async def send_emoji(self, emoji_base64: str) -> bool: """发送表情包 diff --git a/src/plugins/built_in/core_actions/plugin.py b/src/plugins/built_in/core_actions/plugin.py index 7f635436a..123ab2a16 100644 --- a/src/plugins/built_in/core_actions/plugin.py +++ b/src/plugins/built_in/core_actions/plugin.py @@ -115,17 +115,18 @@ class ReplyAction(BaseAction): # 构建回复文本 reply_text = "" first_replied = False + reply_to_platform_id = f"{platform}:{user_id}" for reply_seg in reply_set: data = reply_seg[1] if not first_replied: if need_reply: - await self.send_text(content=data, reply_to=reply_to, typing=False) + await self.send_text(content=data, reply_to=reply_to, reply_to_platform_id=reply_to_platform_id, typing=False) first_replied = True else: - await self.send_text(content=data, typing=False) + await self.send_text(content=data, reply_to_platform_id=reply_to_platform_id, typing=False) first_replied = True else: - await self.send_text(content=data, typing=True) + await self.send_text(content=data, reply_to_platform_id=reply_to_platform_id, typing=True) reply_text += data # 存储动作记录