fix(chat): 修复消息打断后的重复处理并优化回复逻辑
本次提交包含两项关键更改: 1. 将 `triggering_user_id` 的设置逻辑从 `ChatterManager` 迁移至 `StreamLoopManager` 的处理循环初期。这确保了触发用户ID能够更早、更可靠地被设置,为回复保护机制提供了正确的上下文,避免了潜在的逻辑错误。 2. 在消息成功打断正在执行的任务后,立即调用 `clear_all_unread_messages`。此举修复了当新消息打断旧任务时,旧消息队列未被清空,导致机器人可能在之后重新处理这些过时消息的缺陷,从而防止了重复响应。
This commit is contained in:
@@ -378,6 +378,11 @@ class StreamLoopManager:
|
||||
if cached_messages:
|
||||
logger.info(f"处理开始前刷新缓存消息: stream={stream_id}, 数量={len(cached_messages)}")
|
||||
|
||||
# 设置触发用户ID,以实现回复保护
|
||||
last_message = context.get_last_message()
|
||||
if last_message:
|
||||
context.triggering_user_id = last_message.user_info.user_id
|
||||
|
||||
# 创建子任务用于刷新能量(不阻塞主流程)
|
||||
energy_task = asyncio.create_task(self._refresh_focus_energy(stream_id))
|
||||
child_tasks.add(energy_task)
|
||||
|
||||
Reference in New Issue
Block a user