From fd851ccf05d99a3c30a2e29d1106e1a7599f9577 Mon Sep 17 00:00:00 2001 From: nagatoquin33 <109957843+nagatoquin33@users.noreply.github.com> Date: Tue, 10 Mar 2026 07:05:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(onebot):=20=E6=AD=A3=E7=A1=AE=E8=AF=86?= =?UTF-8?q?=E5=88=AB=20QQ=20=E8=A1=A8=E6=83=85=E5=8C=85=20(subType=3D1)=20?= =?UTF-8?q?(#99=20@nagatoquin33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(onebot): 正确识别 QQ 表情包 (subType=1) * refactor(onebot): 安全处理 sub_type 转换,只在有效时包含 sub_type 键 --- .../platform/adapters/onebot_adapter.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/platform/adapters/onebot_adapter.py b/src/infrastructure/platform/adapters/onebot_adapter.py index 0a7b240..774f60e 100644 --- a/src/infrastructure/platform/adapters/onebot_adapter.py +++ b/src/infrastructure/platform/adapters/onebot_adapter.py @@ -257,10 +257,24 @@ class OneBotAdapter(PlatformAdapter): ) elif seg_type == "image": + # QQ 平台: subType=1 表示表情包,通过 raw_data 传递给下游统计 + sub_type = seg_data.get("subType", seg_data.get("sub_type")) + # 安全地转换为整数,防止非数字值导致异常 + try: + is_sticker = int(sub_type) == 1 + except (TypeError, ValueError): + is_sticker = False + # 只在 sub_type 有效时包含在 raw_data 中 + raw_data: dict[str, Any] = {"summary": seg_data.get("summary", "")} + if sub_type is not None: + raw_data["sub_type"] = int(sub_type) contents.append( MessageContent( - type=MessageContentType.IMAGE, + type=MessageContentType.EMOJI + if is_sticker + else MessageContentType.IMAGE, url=seg_data.get("url", seg_data.get("file", "")), + raw_data=raw_data, ) )