feat(affinity-flow): 优化提及检测逻辑和阈值配置

- 简化提及检测逻辑,移除冗余的私聊检查变量
- 使用配置项 mention_bot_adjustment_threshold 替换硬编码的50%阈值
- 在消息处理中清除开头可能存在的空行
- 增加首次认识用户的信息存储方法,避免未知用户处理逻辑
- 调整消息管理器检查间隔从2秒到5秒,减少系统负载
- 修复计划执行器中用户ID比较逻辑,防止自我回复死循环
This commit is contained in:
Windpicker-owo
2025-09-21 18:01:38 +08:00
parent 444f1ca315
commit b5573333f8
6 changed files with 35 additions and 15 deletions

View File

@@ -164,7 +164,28 @@ class PersonInfoManager:
except Exception as e:
logger.error(f"根据用户名 {person_name} 获取用户ID时出错 (SQLAlchemy): {e}")
return ""
@staticmethod
async def first_knowing_some_one(platform: str, user_id: str, user_nickname: str, user_cardname: str):
"""判断是否认识某人"""
person_id = PersonInfoManager.get_person_id(platform, user_id)
# 生成唯一的 person_name
person_info_manager = get_person_info_manager()
unique_nickname = await person_info_manager._generate_unique_person_name(user_nickname)
data = {
"platform": platform,
"user_id": user_id,
"nickname": user_nickname,
"konw_time": int(time.time()),
"person_name": unique_nickname, # 使用唯一的 person_name
}
# 先创建用户基本信息,使用安全创建方法避免竞态条件
await person_info_manager._safe_create_person_info(person_id=person_id, data=data)
# 更新昵称
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):
"""创建一个项"""