From d853bfde84454aed862e9c8ad126fa6a1988a1a2 Mon Sep 17 00:00:00 2001 From: Venus Yan Date: Tue, 23 Dec 2025 08:31:32 -0500 Subject: [PATCH] perf: handle unsupported message types with logging in OneBot adapter (#4164) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Handle unsupported message types with logging 解决else 分支中对未知消息类型毫无防御,直接索引ComponentTypes[t],导致新类型markdown类信息报错并炸掉事件管道,且对应群聊单群永久不响应插件;尝试支持markdown类型进行支持但未经过测试 * chore: ruff format * chore: ruff format --------- Co-authored-by: Soulter <905617992@qq.com> --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 52dd21d56..496726822 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -385,10 +385,25 @@ class AiocqhttpAdapter(Platform): logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") message_str += "".join(at_parts) + elif t == "markdown": + text = m["data"].get("markdown") or m["data"].get("content", "") + abm.message.append(Plain(text=text)) + message_str += text else: for m in m_group: - a = ComponentTypes[t](**m["data"]) - abm.message.append(a) + try: + if t not in ComponentTypes: + logger.warning( + f"不支持的消息段类型,已忽略: {t}, data={m['data']}" + ) + continue + a = ComponentTypes[t](**m["data"]) + abm.message.append(a) + except Exception as e: + logger.exception( + f"消息段解析失败: type={t}, data={m['data']}. {e}" + ) + continue abm.timestamp = int(time.time()) abm.message_str = message_str