跟新dev的修改

This commit is contained in:
UnCLAS-Prommer
2025-07-08 23:35:38 +08:00
12 changed files with 344 additions and 366 deletions

View File

@@ -324,8 +324,6 @@ async def clear_temp_emoji() -> None:
os.remove(file_path)
logger.debug(f"[清理] 删除: {filename}")
logger.info("[清理] 完成")
async def clean_unused_emojis(emoji_dir: str, emoji_objects: List["MaiEmoji"], removed_count: int) -> int:
"""清理指定目录中未被 emoji_objects 追踪的表情包文件"""
@@ -590,7 +588,7 @@ class EmojiManager:
"""定期检查表情包完整性和数量"""
await self.get_all_emoji_from_db()
while True:
logger.info("[扫描] 开始检查表情包完整性...")
# logger.info("[扫描] 开始检查表情包完整性...")
await self.check_emoji_file_integrity()
await clear_temp_emoji()
logger.info("[扫描] 开始扫描新表情包...")

View File

@@ -110,15 +110,13 @@ class HeartFCMessageReceiver:
# current_time = time.strftime("%H:%M:%S", time.localtime(message.message_info.time))
current_talk_frequency = global_config.chat.get_current_talk_frequency(chat.stream_id)
# 如果消息中包含图片标识,则日志展示为图片
# 如果消息中包含图片标识,则将 [picid:...] 替换为 [图片]
picid_pattern = r"\[picid:([^\]]+)\]"
processed_plain_text = re.sub(picid_pattern, "[图片]", message.processed_plain_text)
picid_match = re.search(r"\[picid:([^\]]+)\]", message.processed_plain_text)
if picid_match:
logger.info(f"[{mes_name}]{userinfo.user_nickname}: [图片] [当前回复频率: {current_talk_frequency}]")
else:
logger.info(
f"[{mes_name}]{userinfo.user_nickname}:{message.processed_plain_text}[当前回复频率: {current_talk_frequency}]"
)
logger.info(f"[{mes_name}]{userinfo.user_nickname}:{processed_plain_text}")
logger.debug(f"[{mes_name}][当前时段回复频率: {current_talk_frequency}]")
# 8. 关系处理
if global_config.relationship.enable_relationship:

View File

@@ -131,7 +131,7 @@ class MessageStorage:
if matched_message:
# 更新找到的消息记录
Messages.update(message_id=qq_message_id).where(Messages.id == matched_message.id).execute()
logger.info(f"更新消息ID成功: {matched_message.message_id} -> {qq_message_id}")
logger.debug(f"更新消息ID成功: {matched_message.message_id} -> {qq_message_id}")
else:
logger.debug("未找到匹配的消息")

View File

@@ -302,50 +302,44 @@ class NormalChat:
logger.info(f"[{self.stream_name}] 在处理上下文中检测到停止信号,退出")
break
# 并行处理兴趣消息
async def process_single_message(msg_id, message, interest_value, is_mentioned):
"""处理单个兴趣消息"""
try:
# 在处理每个消息前检查停止状态
if self._disabled:
logger.debug(f"[{self.stream_name}] 处理消息时检测到停用,跳过消息 {msg_id}")
return
semaphore = asyncio.Semaphore(5)
# 处理消息
self.adjust_reply_frequency()
async def process_and_acquire(msg_id, message, interest_value, is_mentioned):
"""处理单个兴趣消息并管理信号量"""
async with semaphore:
try:
# 在处理每个消息前检查停止状态
if self._disabled:
logger.debug(
f"[{self.stream_name}] 处理消息时检测到停用,跳过消息 {msg_id}"
)
return
await self.normal_response(
message=message,
is_mentioned=is_mentioned,
interested_rate=interest_value * self.willing_amplifier,
)
except asyncio.CancelledError:
logger.debug(f"[{self.stream_name}] 处理消息 {msg_id} 时被取消")
raise # 重新抛出取消异常
except Exception as e:
logger.error(f"[{self.stream_name}] 处理兴趣消息{msg_id}时出错: {e}")
# 不打印完整traceback避免日志污染
finally:
# 无论如何都要清理消息
self.interest_dict.pop(msg_id, None)
# 处理消息
self.adjust_reply_frequency()
# 创建并行任务列表
coroutines = []
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
coroutine = process_single_message(msg_id, message, interest_value, is_mentioned)
coroutines.append(coroutine)
await self.normal_response(
message=message,
is_mentioned=is_mentioned,
interested_rate=interest_value * self.willing_amplifier,
)
except asyncio.CancelledError:
logger.debug(f"[{self.stream_name}] 处理消息 {msg_id} 时被取消")
raise # 重新抛出取消异常
except Exception as e:
logger.error(f"[{self.stream_name}] 处理兴趣消息{msg_id}时出错: {e}")
# 不打印完整traceback避免日志污染
finally:
# 无论如何都要清理消息
self.interest_dict.pop(msg_id, None)
# 并行执行所有任务,限制并发数量避免资源过度消耗
if coroutines:
# 使用信号量控制并发数最多同时处理5个消息
semaphore = asyncio.Semaphore(5)
tasks = [
process_and_acquire(msg_id, message, interest_value, is_mentioned)
for msg_id, (message, interest_value, is_mentioned) in items_to_process
]
async def limited_process(coroutine, sem):
async with sem:
await coroutine
limited_tasks = [limited_process(coroutine, semaphore) for coroutine in coroutines]
await asyncio.gather(*limited_tasks, return_exceptions=True)
if tasks:
await asyncio.gather(*tasks, return_exceptions=True)
except asyncio.CancelledError:
logger.info(f"[{self.stream_name}] 处理上下文时任务被取消")
@@ -591,10 +585,21 @@ class NormalChat:
)
response_set, plan_result = results
except asyncio.TimeoutError:
gen_timed_out = not gen_task.done()
plan_timed_out = not plan_task.done()
timeout_details = []
if gen_timed_out:
timeout_details.append("回复生成(gen)")
if plan_timed_out:
timeout_details.append("动作规划(plan)")
timeout_source = "".join(timeout_details)
logger.warning(
f"[{self.stream_name}] 并行执行回复生成和动作规划超时 ({gather_timeout}秒),正在取消相关任务..."
f"[{self.stream_name}] {timeout_source} 任务超时 ({global_config.chat.thinking_timeout}秒),正在取消相关任务..."
)
print(f"111{self.timeout_count}")
# print(f"111{self.timeout_count}")
self.timeout_count += 1
if self.timeout_count > 5:
logger.warning(

View File

@@ -551,6 +551,9 @@ def build_readable_messages(
show_actions: 是否显示动作记录
"""
# 创建messages的深拷贝避免修改原始列表
if not messages:
return ""
copy_messages = [msg.copy() for msg in messages]
if show_actions and copy_messages: