feat: 对aiocqhttp中, At字段新增处理: 现在At字段同时也会被解析为文本信息(但消息链并没有修改, 只是在用于llm请求的文本中添加了At信息)

This commit is contained in:
anka
2025-05-11 22:57:50 +08:00
parent 878a106877
commit 5aeca9662b
@@ -287,6 +287,31 @@ class AiocqhttpAdapter(Platform):
logger.error(f"获取引用消息失败: {e}")
a = ComponentTypes[t](**m["data"]) # noqa: F405
abm.message.append(a)
elif t == "at":
for m in m_group:
try:
at_info = await self.bot.call_action(
action="get_stranger_info",
user_id=int(m["data"]["qq"]),
)
if at_info:
nickname = at_info.get("nick", "")
abm.message.append(
At(
qq=m["data"]["qq"],
name=nickname,
)
)
# 兼容文本消息
message_str += f"@{nickname} "
else:
abm.message.append(
At(qq=m["data"]["qq"], name="")
) # noqa: F405
except ActionFailed as e:
logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。")
except BaseException as e:
logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。")
else:
for m in m_group:
a = ComponentTypes[t](**m["data"]) # noqa: F405