refactor: 移除对机器人自身用户ID的特殊处理,统一使用QQ号进行比较
This commit is contained in:
@@ -280,8 +280,6 @@ class MessageStorageBatcher:
|
||||
user_platform = user_info_dict.get("platform")
|
||||
user_id = user_info_dict.get("user_id")
|
||||
# 将机器人自己的user_id标记为"SELF",增强对自我身份的识别
|
||||
if user_id == global_config.bot.qq_account:
|
||||
user_id = "SELF"
|
||||
user_nickname = user_info_dict.get("user_nickname")
|
||||
user_cardname = user_info_dict.get("user_cardname")
|
||||
|
||||
@@ -630,9 +628,6 @@ class MessageStorage:
|
||||
|
||||
user_platform = user_info_dict.get("platform")
|
||||
user_id = user_info_dict.get("user_id")
|
||||
# 将机器人自己的user_id标记为"SELF",增强对自我身份的识别
|
||||
if user_id == global_config.bot.qq_account:
|
||||
user_id = "SELF"
|
||||
user_nickname = user_info_dict.get("user_nickname")
|
||||
user_cardname = user_info_dict.get("user_cardname")
|
||||
|
||||
|
||||
@@ -1901,6 +1901,8 @@ class DefaultReplyer:
|
||||
# 获取用户ID
|
||||
person_info_manager = get_person_info_manager()
|
||||
person_id = await person_info_manager.get_person_id_by_person_name(sender)
|
||||
if person_id == "SELF":
|
||||
return f"你将要回复的是你自己发送的消息。"
|
||||
if not person_id:
|
||||
logger.warning(f"未找到用户 {sender} 的ID,跳过信息提取")
|
||||
return f"你完全不认识{sender},不理解ta的相关信息。"
|
||||
|
||||
@@ -44,8 +44,8 @@ def replace_user_references_sync(
|
||||
|
||||
if name_resolver is None:
|
||||
def default_resolver(platform: str, user_id: str) -> str:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (user_id == "SELF" or user_id == global_config.bot.qq_account):
|
||||
# 检查是否是机器人自己
|
||||
if replace_bot_name and (user_id == str(global_config.bot.qq_account)):
|
||||
return f"{global_config.bot.nickname}(你)"
|
||||
# 同步函数中无法使用异步的 get_value,直接返回 user_id
|
||||
# 建议调用方使用 replace_user_references_async 以获取完整的用户名
|
||||
@@ -61,7 +61,7 @@ def replace_user_references_sync(
|
||||
bbb = match[2]
|
||||
try:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (bbb == "SELF" or bbb == global_config.bot.qq_account):
|
||||
if replace_bot_name and (bbb == str(global_config.bot.qq_account)):
|
||||
reply_person_name = f"{global_config.bot.nickname}(你)"
|
||||
else:
|
||||
reply_person_name = name_resolver(platform, bbb) or aaa
|
||||
@@ -81,8 +81,8 @@ def replace_user_references_sync(
|
||||
aaa = m.group(1)
|
||||
bbb = m.group(2)
|
||||
try:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (bbb == "SELF" or bbb == global_config.bot.qq_account):
|
||||
# 检查是否是机器人自己
|
||||
if replace_bot_name and (bbb == str(global_config.bot.qq_account)):
|
||||
at_person_name = f"{global_config.bot.nickname}(你)"
|
||||
else:
|
||||
at_person_name = name_resolver(platform, bbb) or aaa
|
||||
@@ -118,8 +118,8 @@ async def replace_user_references_async(
|
||||
"""
|
||||
if name_resolver is None:
|
||||
async def default_resolver(platform: str, user_id: str) -> str:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (user_id == "SELF" or user_id == global_config.bot.qq_account):
|
||||
# 检查是否是机器人自己
|
||||
if replace_bot_name and (user_id == str(global_config.bot.qq_account)):
|
||||
return f"{global_config.bot.nickname}(你)"
|
||||
person_id = PersonInfoManager.get_person_id(platform, user_id)
|
||||
person_info = await person_info_manager.get_values(person_id, ["person_name"])
|
||||
@@ -134,8 +134,8 @@ async def replace_user_references_async(
|
||||
aaa = match.group(1)
|
||||
bbb = match.group(2)
|
||||
try:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (bbb == "SELF" or bbb == global_config.bot.qq_account):
|
||||
# 检查是否是机器人自己
|
||||
if replace_bot_name and (bbb == str(global_config.bot.qq_account)):
|
||||
reply_person_name = f"{global_config.bot.nickname}(你)"
|
||||
else:
|
||||
reply_person_name = await name_resolver(platform, bbb) or aaa
|
||||
@@ -155,8 +155,8 @@ async def replace_user_references_async(
|
||||
aaa = m.group(1)
|
||||
bbb = m.group(2)
|
||||
try:
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (bbb == "SELF" or bbb == global_config.bot.qq_account):
|
||||
# 检查是否是机器人自己
|
||||
if replace_bot_name and (bbb == str(global_config.bot.qq_account)):
|
||||
at_person_name = f"{global_config.bot.nickname}(你)"
|
||||
else:
|
||||
at_person_name = await name_resolver(platform, bbb) or aaa
|
||||
@@ -640,7 +640,7 @@ async def _build_readable_messages_internal(
|
||||
# 根据 replace_bot_name 参数决定是否替换机器人名称
|
||||
person_name: str
|
||||
# 检查是否是机器人自己(支持SELF标记或直接比对QQ号)
|
||||
if replace_bot_name and (user_id == "SELF" or user_id == global_config.bot.qq_account):
|
||||
if replace_bot_name and user_id == str(global_config.bot.qq_account):
|
||||
person_name = f"{global_config.bot.nickname}(你)"
|
||||
else:
|
||||
person_id = PersonInfoManager.get_person_id(platform, user_id)
|
||||
@@ -656,8 +656,8 @@ async def _build_readable_messages_internal(
|
||||
else:
|
||||
person_name = "某人"
|
||||
|
||||
# 在用户名后面添加 QQ 号, 但机器人本体不用(包括SELF标记)
|
||||
if user_id != global_config.bot.qq_account and user_id != "SELF":
|
||||
# 在用户名后面添加 QQ 号, 但机器人本体不用
|
||||
if user_id != str(global_config.bot.qq_account):
|
||||
person_name = f"{person_name}({user_id})"
|
||||
|
||||
# 使用独立函数处理用户引用格式
|
||||
@@ -1026,7 +1026,7 @@ async def build_readable_messages(
|
||||
actions = [
|
||||
{
|
||||
"time": a.time,
|
||||
"user_id": global_config.bot.qq_account,
|
||||
"user_id": str(global_config.bot.qq_account),
|
||||
"user_nickname": global_config.bot.nickname,
|
||||
"user_cardname": "",
|
||||
"processed_plain_text": f"{a.action_prompt_display}",
|
||||
|
||||
@@ -166,7 +166,7 @@ async def get_recent_group_speaker(chat_stream_id: str, sender, limit: int = 12)
|
||||
)
|
||||
if (
|
||||
(user_info.platform, user_info.user_id) != sender
|
||||
and user_info.user_id != global_config.bot.qq_account
|
||||
and user_info.user_id != str(global_config.bot.qq_account)
|
||||
and (user_info.platform, user_info.user_id, user_info.user_nickname) not in who_chat_in_group
|
||||
and len(who_chat_in_group) < 5
|
||||
): # 排除重复,排除消息发送者,排除bot,限制加载的关系数目
|
||||
|
||||
Reference in New Issue
Block a user