refactor(chat): 重构消息管理器以使用集中式聊天流API

移除对context.chat_stream的直接依赖,改为通过get_chat_manager().get_stream()统一获取聊天流实例。这提高了模块独立性,符合"高内聚、低耦合"原则。

- 在MessageManager中统一使用chat_api获取stream实例
- 移除mood_manager中直接更新chat_stream的逻辑
- 在affinity_flow_chatter中统一处理兴趣度更新
- 消除直接属性访问带来的强耦合依赖
This commit is contained in:
Windpicker-owo
2025-09-26 11:45:20 +08:00
parent a67b78b551
commit 66f9b9b84f
3 changed files with 29 additions and 24 deletions

View File

@@ -125,17 +125,17 @@ class ChatterActionPlanner:
logger.info(f"兴趣度不足 ({latest_score.total_score:.2f}),移除回复")
reply_not_available = True
# 更新ChatStream的兴趣度数据
from src.plugin_system.apis.chat_api import get_chat_manager
chat_stream = get_chat_manager().get_stream(self.chat_id)
chat_stream.add_message_interest(score)
logger.debug(f"已更新聊天 {self.chat_id} 的ChatStream兴趣度分数: {score:.3f}")
# 更新情绪状态和ChatStream兴趣度数据
if latest_message and score > 0:
chat_mood = mood_manager.get_mood_by_chat_id(self.chat_id)
await chat_mood.update_mood_by_message(latest_message, score)
logger.debug(f"已更新聊天 {self.chat_id} 的情绪状态,兴趣度: {score:.3f}")
elif latest_message:
# 即使不更新情绪状态也要更新ChatStream的兴趣度数据
chat_mood = mood_manager.get_mood_by_chat_id(self.chat_id)
if hasattr(chat_mood, 'chat_stream') and chat_mood.chat_stream:
chat_mood.chat_stream.add_message_interest(score)
logger.debug(f"已更新聊天 {self.chat_id} 的ChatStream兴趣度分数: {score:.3f}")
# base_threshold = self.interest_scoring.reply_threshold
# 检查兴趣度是否达到非回复动作阈值