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))