feat(sleep): 细化唤醒机制,实现分聊天的起床气

先前的唤醒与起床气机制是全局性的,一个聊天中的频繁消息会导致Bot对所有聊天都表现出“起床气”状态,这在多聊天场景下体验不佳。

本次更新将唤醒机制与具体的 `chat_id` 进行绑定,实现了更精细化的交互逻辑:
- Bot被吵醒后,其“起床气”状态将只针对吵醒它的聊天生效。
- 在此期间,Bot会忽略其他所有聊天的消息,专注于处理来自触发唤醒的聊天的消息。
- Prompt现在会优先注入起床气相关的描述,确保响应符合当前状态。

此外,为了更准确地捕捉唤醒意图,在群聊中,即使没有@提及,只要消息包含Bot的昵称或别名,也会被视为一次有效“提及”,从而累加唤醒值。
This commit is contained in:
tt-P607
2025-09-27 00:58:41 +08:00
parent 28a2a4b0c8
commit 7f39f6f649
4 changed files with 57 additions and 9 deletions

View File

@@ -180,8 +180,14 @@ class MessageManager:
for message in unread_messages:
is_mentioned = message.is_mentioned or False
if not is_mentioned and not is_private:
bot_names = [global_config.bot.nickname] + global_config.bot.alias_names
if any(name in message.processed_plain_text for name in bot_names):
is_mentioned = True
logger.debug(f"通过关键词 '{next((name for name in bot_names if name in message.processed_plain_text), '')}' 匹配将消息标记为 'is_mentioned'")
if is_private or is_mentioned:
if self.wakeup_manager.add_wakeup_value(is_private, is_mentioned):
if self.wakeup_manager.add_wakeup_value(is_private, is_mentioned, chat_id=stream_id):
was_woken_up = True
break # 一旦被吵醒,就跳出循环并处理消息
@@ -190,6 +196,12 @@ class MessageManager:
return # 退出,不处理消息
logger.info(f"Bot被聊天流 {stream_id} 中的消息吵醒,继续处理。")
elif self.sleep_manager.is_woken_up():
angry_chat_id = self.wakeup_manager.angry_chat_id
if stream_id != angry_chat_id:
logger.debug(f"Bot处于WOKEN_UP状态但当前流 {stream_id} 不是触发唤醒的流 {angry_chat_id},跳过处理。")
return # 退出,不处理此流的消息
logger.info(f"Bot处于WOKEN_UP状态处理触发唤醒的流 {stream_id}")
# --- 睡眠状态检查结束 ---
logger.debug(f"开始处理聊天流 {stream_id}{len(unread_messages)} 条未读消息")