fix: 兴趣消息恢复改为并发
This commit is contained in:
@@ -225,9 +225,9 @@ class MessageManager:
|
|||||||
if (
|
if (
|
||||||
# message.apply_set_reply_logic # 检查标记
|
# message.apply_set_reply_logic # 检查标记
|
||||||
# and message.is_head
|
# and message.is_head
|
||||||
message.is_head
|
# message.is_head
|
||||||
and (thinking_messages_count > 3 or thinking_messages_length > 200)
|
# and (thinking_messages_count > 3 or thinking_messages_length > 200) and
|
||||||
and not message.is_private_message()
|
not message.is_private_message()
|
||||||
):
|
):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"[{message.chat_stream.stream_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}..."
|
f"[{message.chat_stream.stream_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}..."
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class NormalChat:
|
|||||||
self.on_switch_to_focus_callback = on_switch_to_focus_callback
|
self.on_switch_to_focus_callback = on_switch_to_focus_callback
|
||||||
|
|
||||||
self._disabled = False # 增加停用标志
|
self._disabled = False # 增加停用标志
|
||||||
|
|
||||||
logger.debug(f"[{self.stream_name}] NormalChat 初始化完成 (异步部分)。")
|
logger.debug(f"[{self.stream_name}] NormalChat 初始化完成 (异步部分)。")
|
||||||
|
|
||||||
# 改为实例方法
|
# 改为实例方法
|
||||||
@@ -211,8 +211,9 @@ class NormalChat:
|
|||||||
if not items_to_process:
|
if not items_to_process:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 处理每条兴趣消息
|
# 并行处理兴趣消息
|
||||||
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
|
async def process_single_message(msg_id, message, interest_value, is_mentioned):
|
||||||
|
"""处理单个兴趣消息"""
|
||||||
try:
|
try:
|
||||||
# 处理消息
|
# 处理消息
|
||||||
if time.time() - self.start_time > 300:
|
if time.time() - self.start_time > 300:
|
||||||
@@ -230,6 +231,24 @@ class NormalChat:
|
|||||||
finally:
|
finally:
|
||||||
self.interest_dict.pop(msg_id, None)
|
self.interest_dict.pop(msg_id, None)
|
||||||
|
|
||||||
|
# 创建并行任务列表
|
||||||
|
tasks = []
|
||||||
|
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
|
||||||
|
task = process_single_message(msg_id, message, interest_value, is_mentioned)
|
||||||
|
tasks.append(task)
|
||||||
|
|
||||||
|
# 并行执行所有任务,限制并发数量避免资源过度消耗
|
||||||
|
if tasks:
|
||||||
|
# 使用信号量控制并发数,最多同时处理5个消息
|
||||||
|
semaphore = asyncio.Semaphore(5)
|
||||||
|
|
||||||
|
async def limited_process(task):
|
||||||
|
async with semaphore:
|
||||||
|
await task
|
||||||
|
|
||||||
|
limited_tasks = [limited_process(task) for task in tasks]
|
||||||
|
await asyncio.gather(*limited_tasks, return_exceptions=True)
|
||||||
|
|
||||||
# 改为实例方法, 移除 chat 参数
|
# 改为实例方法, 移除 chat 参数
|
||||||
async def normal_response(self, message: MessageRecv, is_mentioned: bool, interested_rate: float) -> None:
|
async def normal_response(self, message: MessageRecv, is_mentioned: bool, interested_rate: float) -> None:
|
||||||
# 新增:如果已停用,直接返回
|
# 新增:如果已停用,直接返回
|
||||||
@@ -238,7 +257,9 @@ class NormalChat:
|
|||||||
return
|
return
|
||||||
|
|
||||||
timing_results = {}
|
timing_results = {}
|
||||||
reply_probability = 1.0 if is_mentioned and global_config.normal_chat.mentioned_bot_inevitable_reply else 0.0 # 如果被提及,且开启了提及必回复,则基础概率为1,否则需要意愿判断
|
reply_probability = (
|
||||||
|
1.0 if is_mentioned and global_config.normal_chat.mentioned_bot_inevitable_reply else 0.0
|
||||||
|
) # 如果被提及,且开启了提及必回复,则基础概率为1,否则需要意愿判断
|
||||||
|
|
||||||
# 意愿管理器:设置当前message信息
|
# 意愿管理器:设置当前message信息
|
||||||
willing_manager.setup(message, self.chat_stream, is_mentioned, interested_rate)
|
willing_manager.setup(message, self.chat_stream, is_mentioned, interested_rate)
|
||||||
@@ -659,7 +680,7 @@ class NormalChat:
|
|||||||
# 执行动作
|
# 执行动作
|
||||||
result = await action_handler.handle_action()
|
result = await action_handler.handle_action()
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
if result and isinstance(result, tuple) and len(result) >= 2:
|
if result and isinstance(result, tuple) and len(result) >= 2:
|
||||||
# handle_action返回 (success: bool, message: str)
|
# handle_action返回 (success: bool, message: str)
|
||||||
success = result[0]
|
success = result[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user