From 5aeca9662b30a246ed637062bd4acff10a042c1a Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Sun, 11 May 2025 22:57:50 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=AF=B9aiocqhttp=E4=B8=AD,=20At?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=96=B0=E5=A2=9E=E5=A4=84=E7=90=86:=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8At=E5=AD=97=E6=AE=B5=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=B9=9F=E4=BC=9A=E8=A2=AB=E8=A7=A3=E6=9E=90=E4=B8=BA=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF(=E4=BD=86=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=93=BE=E5=B9=B6=E6=B2=A1=E6=9C=89=E4=BF=AE=E6=94=B9,=20?= =?UTF-8?q?=E5=8F=AA=E6=98=AF=E5=9C=A8=E7=94=A8=E4=BA=8Ellm=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84=E6=96=87=E6=9C=AC=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86At=E4=BF=A1=E6=81=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 97754f2c9..4786b996c 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -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 From 4bef5e8313444dbcb0a84cf6fad69fb3e791ff66 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 00:21:48 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8Dmessage=5Fstr?= =?UTF-8?q?=E8=A2=AB=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sources/aiocqhttp/aiocqhttp_platform_adapter.py | 10 +++------- 1 file changed, 3 insertions(+), 7 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..0896e6ccb 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -165,9 +165,7 @@ class AiocqhttpAdapter(Platform): if "sub_type" in event: if event["sub_type"] == "poke" and "target_id" in event: - abm.message.append( - Poke(qq=str(event["target_id"]), type="poke") - ) # noqa: F405 + abm.message.append(Poke(qq=str(event["target_id"]), type="poke")) # noqa: F405 return abm @@ -218,7 +216,7 @@ class AiocqhttpAdapter(Platform): a = None if t == "text": # 合并相邻文本段 - message_str = "".join(m["data"]["text"] for m in m_group).strip() + message_str += "".join(m["data"]["text"] for m in m_group).strip() a = ComponentTypes[t](text=message_str) # noqa: F405 abm.message.append(a) @@ -305,9 +303,7 @@ class AiocqhttpAdapter(Platform): # 兼容文本消息 message_str += f"@{nickname} " else: - abm.message.append( - At(qq=m["data"]["qq"], name="") - ) # noqa: F405 + abm.message.append(At(qq=m["data"]["qq"], name="")) # noqa: F405 except ActionFailed as e: logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") except BaseException as e: 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 3/6] =?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: From 77c823c100c89518f295a8f412cec8a868c853d2 Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Mon, 12 May 2025 11:32:40 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=85=A8?= =?UTF-8?q?=E4=BD=93=E6=88=90=E5=91=98=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sources/aiocqhttp/aiocqhttp_platform_adapter.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index eb50ad679..cbf40edaa 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -217,9 +217,9 @@ class AiocqhttpAdapter(Platform): for t, m_group in itertools.groupby(event.message, key=lambda x: x["type"]): a = None if t == "text": - # 合并相邻文本段 - message_str += "".join(m["data"]["text"] for m in m_group).strip() - a = ComponentTypes[t](text=message_str) # noqa: F405 + current_text = "".join(m["data"]["text"] for m in m_group).strip() + message_str += current_text + a = ComponentTypes[t](text=current_text) # noqa: F405 abm.message.append(a) elif t == "file": @@ -292,6 +292,11 @@ class AiocqhttpAdapter(Platform): for m in m_group: try: + if m["data"]["qq"] == "all": + abm.message.append(At(qq="all", name="全体成员")) + message_str += "@全体成员 " + continue + at_info = await self.bot.call_action( action="get_stranger_info", user_id=int(m["data"]["qq"]), From a730cee7fd64daead7e8d5fd59ab8d135bc34ce6 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 14:48:31 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20at=E5=85=A8=E4=BD=93=E4=B8=8D?= =?UTF-8?q?=E5=8A=A0=E5=85=A5message=5Fstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index cbf40edaa..9d882741c 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -294,7 +294,6 @@ class AiocqhttpAdapter(Platform): try: if m["data"]["qq"] == "all": abm.message.append(At(qq="all", name="全体成员")) - message_str += "@全体成员 " continue at_info = await self.bot.call_action( From 3ad2c46f3fcb48136692b131b1bfa97a235d09b6 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 15:04:23 +0800 Subject: [PATCH 6/6] =?UTF-8?q?perf:=20tg=E9=80=82=E9=85=8D=E5=99=A8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5aiocqhttp=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/telegram/tg_adapter.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index a2ce88736..b13b60d7d 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -282,10 +282,12 @@ class TelegramPlatformAdapter(Platform): entity.offset + 1 : entity.offset + entity.length ] message.message.append(Comp.At(qq=name, name=name)) - plain_text = ( - plain_text[: entity.offset] - + plain_text[entity.offset + entity.length :] - ) + # 如果mention是当前bot则移除;否则保留 + if name.lower() == context.bot.username.lower(): + plain_text = ( + plain_text[: entity.offset] + + plain_text[entity.offset + entity.length :] + ) if plain_text: message.message.append(Comp.Plain(plain_text))