style: 格式化代码

This commit is contained in:
John Richard
2025-10-02 19:38:39 +08:00
parent d5627b0661
commit ecb02cae31
111 changed files with 2344 additions and 2316 deletions

View File

@@ -1,4 +1,3 @@
import asyncio
import copy
import datetime
import hashlib
@@ -145,7 +144,7 @@ class PersonInfoManager:
except Exception as e:
logger.error(f"根据用户名 {person_name} 获取用户ID时出错: {e}")
return ""
@staticmethod
async def first_knowing_some_one(platform: str, user_id: str, user_nickname: str, user_cardname: str):
"""判断是否认识某人"""
@@ -166,7 +165,7 @@ class PersonInfoManager:
await person_info_manager.update_one_field(
person_id=person_id, field_name="nickname", value=user_nickname, data=data
)
@staticmethod
async def create_person_info(person_id: str, data: Optional[dict] = None):
"""创建一个项"""
@@ -491,7 +490,9 @@ class PersonInfoManager:
async def _db_check_name_exists_async(name_to_check):
async with get_db_session() as session:
result = await session.execute(select(PersonInfo).where(PersonInfo.person_name == name_to_check))
result = await session.execute(
select(PersonInfo).where(PersonInfo.person_name == name_to_check)
)
record = result.scalar()
return record is not None
@@ -552,7 +553,6 @@ class PersonInfoManager:
else:
logger.debug(f"删除失败:未找到 person_id={person_id} 或删除未影响行")
@staticmethod
async def get_value(person_id: str, field_name: str) -> Any:
"""获取单个字段值(同步版本)"""
@@ -623,6 +623,7 @@ class PersonInfoManager:
result[field_name] = copy.deepcopy(person_info_default.get(field_name))
return result
@staticmethod
async def get_specific_value_list(
field_name: str,
@@ -694,7 +695,7 @@ class PersonInfoManager:
return record, False # 其他协程已创建,返回现有记录
# 如果仍然失败,重新抛出异常
raise e
unique_nickname = await self._generate_unique_person_name(nickname)
initial_data = {
"person_id": person_id,

View File

@@ -303,12 +303,14 @@ class RelationshipBuilder:
if not self.person_engaged_cache:
return f"{self.log_prefix} 关系缓存为空"
status_lines = [f"{self.log_prefix} 关系缓存状态:",
f"最后处理消息时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.last_processed_message_time)) if self.last_processed_message_time > 0 else '未设置'}",
f"最后清理时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.last_cleanup_time)) if self.last_cleanup_time > 0 else '执行'}",
f"总用户数:{len(self.person_engaged_cache)}",
f"清理配置{'启用' if SEGMENT_CLEANUP_CONFIG['enable_cleanup'] else '禁用'} (最大保存{SEGMENT_CLEANUP_CONFIG['max_segment_age_days']}天, 每用户最多{SEGMENT_CLEANUP_CONFIG['max_segments_per_user']}段)",
""]
status_lines = [
f"{self.log_prefix} 关系缓存状态:",
f"最后处理消息时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.last_processed_message_time)) if self.last_processed_message_time > 0 else '设置'}",
f"最后清理时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.last_cleanup_time)) if self.last_cleanup_time > 0 else '未执行'}",
f"总用户数{len(self.person_engaged_cache)}",
f"清理配置:{'启用' if SEGMENT_CLEANUP_CONFIG['enable_cleanup'] else '禁用'} (最大保存{SEGMENT_CLEANUP_CONFIG['max_segment_age_days']}天, 每用户最多{SEGMENT_CLEANUP_CONFIG['max_segments_per_user']}段)",
"",
]
for person_id, segments in self.person_engaged_cache.items():
total_count = self._get_total_message_count(person_id)
@@ -369,7 +371,7 @@ class RelationshipBuilder:
for person_id, segments in self.person_engaged_cache.items():
total_message_count = self._get_total_message_count(person_id)
person_name = get_person_info_manager().get_value(person_id, "person_name") or person_id
if total_message_count >= max_build_threshold or (
total_message_count >= 5 and (immediate_build == person_id or immediate_build == "all")
):
@@ -428,7 +430,9 @@ class RelationshipBuilder:
start_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(start_time))
# 获取该段的消息(包含边界)
segment_messages = await get_raw_msg_by_timestamp_with_chat_inclusive(self.chat_id, start_time, end_time)
segment_messages = await get_raw_msg_by_timestamp_with_chat_inclusive(
self.chat_id, start_time, end_time
)
logger.debug(
f"消息段: {start_date} - {time.strftime('%Y-%m-%d %H:%M', time.localtime(end_time))}, 消息数: {len(segment_messages)}"
)

View File

@@ -1,7 +1,6 @@
import time
import traceback
import orjson
import random
from typing import List, Dict, Any
from json_repair import repair_json