feat(affinity-flow): 增强关系追踪系统的人设集成和逻辑严谨性
- 在关系追踪器中集成bot人设信息,从性格视角分析用户互动 - 添加严格的关系分数档次定义和现实发展逻辑约束 - 改进提示词工程,要求详细的性格观察和互动记忆记录 - 单次互动加分限制在合理范围内(0.05-0.1),防止跳跃式关系提升 - 优化关系印象描述要求(100-200字),包含用户性格特点和深刻记忆 refactor(planner): 简化消息数据处理流程 - 使用StreamContext对象替代原始的message_data字典 - 移除冗余的消息数据准备步骤,直接从context获取未读消息 - 统一规划器接口,提高代码可读性和维护性 fix(person-info): 添加napcat到qq平台的用户ID迁移机制 - 为qq平台生成person_id时检查是否存在napcat平台的相同用户 - 如果存在则自动迁移记录并更新平台信息 - 确保用户身份在不同平台间的正确识别和延续 fix(plan-executor): 修复自我回复检测逻辑 - 使用action_message.user_info.user_id替代原始字典访问 - 防止因消息格式变化导致的自我回复检测失效 chore(config): 更新默认平台配置为qq - 将napcat_adapter插件的默认平台名称从napcat改为qq - 保持与现有部署环境的一致性
This commit is contained in:
@@ -93,10 +93,50 @@ class PersonInfoManager:
|
||||
|
||||
if "-" in platform:
|
||||
platform = platform.split("-")[1]
|
||||
|
||||
# 在此处打一个补丁,如果platform为qq,尝试生成id后检查是否存在,如果不存在,则将平台换为napcat后再次检查,如果存在,则更新原id为platform为qq的id
|
||||
components = [platform, str(user_id)]
|
||||
key = "_".join(components)
|
||||
return hashlib.md5(key.encode()).hexdigest()
|
||||
|
||||
# 如果不是 qq 平台,直接返回计算的 id
|
||||
if platform != "qq":
|
||||
return hashlib.md5(key.encode()).hexdigest()
|
||||
|
||||
qq_id = hashlib.md5(key.encode()).hexdigest()
|
||||
# 对于 qq 平台,先检查该 person_id 是否已存在;如果存在直接返回
|
||||
def _db_check_and_migrate_sync(p_id: str, raw_user_id: str):
|
||||
try:
|
||||
with get_db_session() as session:
|
||||
# 检查 qq_id 是否存在
|
||||
existing_qq = session.execute(select(PersonInfo).where(PersonInfo.person_id == p_id)).scalar()
|
||||
if existing_qq:
|
||||
return p_id
|
||||
|
||||
# 如果 qq_id 不存在,尝试使用 napcat 作为平台生成对应 id 并检查
|
||||
nap_components = ["napcat", str(raw_user_id)]
|
||||
nap_key = "_".join(nap_components)
|
||||
nap_id = hashlib.md5(nap_key.encode()).hexdigest()
|
||||
|
||||
existing_nap = session.execute(select(PersonInfo).where(PersonInfo.person_id == nap_id)).scalar()
|
||||
if not existing_nap:
|
||||
# napcat 也不存在,返回 qq_id(未命中)
|
||||
return p_id
|
||||
|
||||
# napcat 存在,迁移该记录:更新 person_id 与 platform -> qq
|
||||
try:
|
||||
# 更新现有 napcat 记录
|
||||
existing_nap.person_id = p_id
|
||||
existing_nap.platform = "qq"
|
||||
existing_nap.user_id = str(raw_user_id)
|
||||
session.commit()
|
||||
return p_id
|
||||
except Exception:
|
||||
session.rollback()
|
||||
return p_id
|
||||
except Exception as e:
|
||||
logger.error(f"检查/迁移 napcat->qq 时出错: {e}")
|
||||
return p_id
|
||||
|
||||
return _db_check_and_migrate_sync(qq_id, user_id)
|
||||
|
||||
async def is_person_known(self, platform: str, user_id: int):
|
||||
"""判断是否认识某人"""
|
||||
|
||||
Reference in New Issue
Block a user