This commit is contained in:
tt-P607
2025-09-20 12:22:15 +08:00
committed by Windpicker-owo
parent d53238dfc9
commit d9f2cd084d
3 changed files with 12 additions and 11 deletions

View File

@@ -39,6 +39,7 @@ class HeartFChatting:
- 初始化聊天模式并记录初始化完成日志
"""
self.context = HfcContext(chat_id)
self.context.new_message_queue = asyncio.Queue()
self.cycle_tracker = CycleTracker(self.context)
self.response_handler = ResponseHandler(self.context)
@@ -108,6 +109,10 @@ class HeartFChatting:
self._loop_task.add_done_callback(self._handle_loop_completion)
logger.info(f"{self.context.log_prefix} HeartFChatting 启动完成")
async def add_message(self, message: Dict[str, Any]):
"""从外部接收新消息并放入队列"""
await self.context.new_message_queue.put(message)
async def stop(self):
"""
停止心跳聊天系统
@@ -362,15 +367,10 @@ class HeartFChatting:
# 核心修复:在睡眠模式(包括失眠)下获取消息时,不过滤命令消息,以确保@消息能被接收
filter_command_flag = not (is_sleeping or is_in_insomnia)
recent_messages = await message_api.get_messages_by_time_in_chat(
chat_id=self.context.stream_id,
start_time=self.context.last_read_time,
end_time=time.time(),
limit=10,
limit_mode="latest",
filter_mai=True,
filter_command=filter_command_flag,
)
# 从队列中获取所有待处理的新消息
recent_messages = []
while not self.context.new_message_queue.empty():
recent_messages.append(await self.context.new_message_queue.get())
has_new_messages = bool(recent_messages)
new_message_count = len(recent_messages)

View File

@@ -117,7 +117,7 @@ class HeartFCMessageReceiver:
subheartflow: SubHeartflow = await heartflow.get_or_create_subheartflow(chat.stream_id) # type: ignore
# subheartflow.add_message_to_normal_chat_cache(message, interested_rate, is_mentioned)
await subheartflow.heart_fc_instance.add_message(message.to_dict())
if global_config.mood.enable_mood:
chat_mood = mood_manager.get_mood_by_chat_id(subheartflow.chat_id)
asyncio.create_task(chat_mood.update_mood_by_message(message, interested_rate))

View File

@@ -9,6 +9,7 @@ from typing import Any, Dict, List, Optional
from json_repair import repair_json
from . import planner_prompts
from src.chat.memory_system.Hippocampus import hippocampus_manager
from src.chat.utils.chat_message_builder import (
build_readable_actions,
@@ -167,7 +168,7 @@ class PlanFilter:
limit=5,
)
actions_before_now_block = build_readable_actions(actions=await actions_before_now)
actions_before_now_block = build_readable_actions(actions=actions_before_now)
actions_before_now_block = f"你刚刚选择并执行过的action是\n{actions_before_now_block}"
self.last_obs_time_mark = time.time()