From e46cf20dd30f7b0e832e62151f1c31fe3c036c4e Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Mon, 12 May 2025 11:22:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8D=E5=86=8D=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=94=A4=E9=86=92=E7=9A=84@=E5=88=B0message=5Fstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 4786b996c..e6ed9205f 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -288,6 +288,8 @@ class AiocqhttpAdapter(Platform): a = ComponentTypes[t](**m["data"]) # noqa: F405 abm.message.append(a) elif t == "at": + first_at_self_processed = False + for m in m_group: try: at_info = await self.bot.call_action( @@ -296,18 +298,23 @@ class AiocqhttpAdapter(Platform): ) if at_info: nickname = at_info.get("nick", "") + is_at_self = str(m["data"]["qq"]) in {abm.self_id, "all"} + abm.message.append( At( qq=m["data"]["qq"], name=nickname, ) ) - # 兼容文本消息 - message_str += f"@{nickname} " + + if is_at_self and not first_at_self_processed: + # 第一个@是机器人,不添加到message_str + first_at_self_processed = True + else: + # 非第一个@机器人或@其他用户,添加到message_str + message_str += f"@{nickname} " else: - abm.message.append( - At(qq=m["data"]["qq"], name="") - ) # noqa: F405 + abm.message.append(At(qq=str(m["data"]["qq"]), name="")) except ActionFailed as e: logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") except BaseException as e: