fix(proactive_thinker): 修复主动思考任务的逻辑缺陷

在 `ColdStartTask` 和 `ProactiveThinkingTask` 中,私聊和群聊任务的执行逻辑存在缺陷。本次提交修复了以下问题:

1.  在冷启动和日常唤醒任务开始时,增加对私聊总开关 `enable_in_private` 的判断,避免在禁用时仍执行扫描。
2.  在日常唤醒任务中,为群聊处理逻辑增加了总开关 `enable_in_group` 的判断。
3.  修复了群聊白名单的判断逻辑,之前无论群聊是否在白名单内都会被唤醒,现在会正确地只唤醒白名单内的群聊。
This commit is contained in:
minecraft1024a
2025-10-05 21:01:56 +08:00
committed by Windpicker-owo
parent 30203f45c3
commit 66a68356a1

View File

@@ -40,6 +40,11 @@ class ColdStartTask(AsyncTask):
try:
logger.info("【冷启动】开始扫描白名单,唤醒沉睡的聊天流...")
# 【修复】增加对私聊总开关的判断
if not global_config.proactive_thinking.enable_in_private:
logger.info("【冷启动】私聊主动思考功能未启用,任务结束。")
return
enabled_private_chats = global_config.proactive_thinking.enabled_private_chats
if not enabled_private_chats:
logger.debug("【冷启动】私聊白名单为空,任务结束。")
@@ -150,7 +155,8 @@ class ProactiveThinkingTask(AsyncTask):
enabled_groups = set(global_config.proactive_thinking.enabled_group_chats)
# 分别处理私聊和群聊
# 1. 处理私聊:直接遍历白名单,确保能覆盖到所有(包括本次运行尚未活跃的)用户
# 1. 处理私聊:首先检查私聊总开关
if global_config.proactive_thinking.enable_in_private:
for chat_id in enabled_private:
try:
platform, user_id_str = chat_id.split(":")
@@ -177,14 +183,15 @@ class ProactiveThinkingTask(AsyncTask):
except Exception as e:
logger.error(f"【日常唤醒】处理私聊用户 {chat_id} 时发生未知错误: {e}", exc_info=True)
# 2. 处理群聊:遍历内存中的活跃流(群聊不存在冷启动问题)
# 2. 处理群聊:首先检查群聊总开关
if global_config.proactive_thinking.enable_in_group:
all_streams = list(self.chat_manager.streams.values())
for stream in all_streams:
if not stream.group_info:
continue # 只处理群聊
# 检查群聊是否在白名单内
if not enabled_groups or f"qq:{stream.group_info.group_id}" in enabled_groups:
# 【修复】检查群聊是否在白名单内
if f"qq:{stream.group_info.group_id}" in enabled_groups:
# 检查冷却时间
recent_messages = await message_api.get_recent_messages(chat_id=stream.stream_id, limit=1)
last_message_time = recent_messages[0]["time"] if recent_messages else stream.create_time