From c28abd4d21575350cc47fdcfcb914ced0989ceaa Mon Sep 17 00:00:00 2001 From: LEN5010 <1649211052@qq.com> Date: Fri, 13 Nov 2026 09:22:04 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20QQ=20=E5=9B=BE=E7=89=87=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E4=B8=8D=E5=86=8D=E6=98=BE=E7=A4=BA=E5=86=85=E9=83=A8?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OneBot 发图时只发送 file 和 sub_type,不再把图片段里给模型看的 summary(插件图片说明、角色表情和本群表情说明)发给协议端。此前 QQ 会把这段说明当作消息预览文字,显示为 [插件 asoul ...] 一类内容。内部记录中的说明保持不变,聊天回看仍能看到 bot 发过什么图。 核对:test_next_platform_protocol 34 项,按 onebot、表情、插件等关键词挑选的 365 项测试,ruff 通过。真实 QQ 预览文字尚未确认。 --- src/len_bot/next/platform/onebot.py | 4 ++-- tests/test_next_platform_protocol.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/len_bot/next/platform/onebot.py b/src/len_bot/next/platform/onebot.py index 51bd52081..3e5870881 100644 --- a/src/len_bot/next/platform/onebot.py +++ b/src/len_bot/next/platform/onebot.py @@ -458,10 +458,10 @@ async def send_message(self, message: ChatMessage, *, image_bytes: bytes | None image_bytes = await asyncio.to_thread(sticker_bytes, image_bytes) wire_image = (None if image_bytes is None else "base64://" + base64.b64encode(image_bytes).decode("ascii")) + # 图片段的 summary 是给模型看的内部说明,不发给平台;QQ 会把它当作消息预览文字。 wire_segments = [ {"type": "at" if segment.type == "mention" else "record" if segment.type == "audio" else segment.type, "data": ( - {"file": wire_image, **{key: segment.data[key] for key in ('summary', 'sub_type') - if key in segment.data}} + {"file": wire_image, **({"sub_type": segment.data["sub_type"]} if "sub_type" in segment.data else {})} if segment.type == "image" else {"qq": "all" if segment.data["user"] == "all" else segment.data["user"].split(":", 1)[1]} if segment.type == "mention" else segment.data)} diff --git a/tests/test_next_platform_protocol.py b/tests/test_next_platform_protocol.py index f40fe9a6e..8b461df46 100644 --- a/tests/test_next_platform_protocol.py +++ b/tests/test_next_platform_protocol.py @@ -165,7 +165,8 @@ async def peer(websocket): segments = requests[1]['params']['message'] assert segments[:2] == [ {'type': 'at', 'data': {'qq': '70001'}}, {'type': 'text', 'data': {'text': '合成回复'}}] - assert {key: value for key, value in segments[2]['data'].items() if key != 'file'} == image_data + assert {key: value for key, value in segments[2]['data'].items() if key != 'file'} == ( + {} if image_type is None else {'sub_type': image_type}) sent = base64.b64decode(segments[2]['data']['file'].removeprefix('base64://')) with Image.open(BytesIO(sent)) as image: assert image.size == ((320, 320) if image_type == 1 else (1024, 1024))