refactor: 移除对机器人自身用户ID的特殊处理,统一使用QQ号进行比较
This commit is contained in:
@@ -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}",
|
||||
|
||||
Reference in New Issue
Block a user