From f7c228ede2caca62accc5cf2414c859bebf90900 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Sat, 24 Jan 2026 14:43:49 +0800 Subject: [PATCH] fix: markdown keyerror or unbound error in aiocqhttp adapter (#4656) * fix: markdown keyerror or unbound error in aiocqhttp adapter * fix: improve exception handling and logging in aiocqhttp adapter --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 29fde59ab..d4d8e1d62 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -62,27 +62,44 @@ class AiocqhttpAdapter(Platform): @self.bot.on_request() async def request(event: Event): - abm = await self.convert_message(event) - if abm: + try: + abm = await self.convert_message(event) + if not abm: + return await self.handle_msg(abm) + except Exception as e: + logger.exception(f"Handle request message failed: {e}") + return @self.bot.on_notice() async def notice(event: Event): - abm = await self.convert_message(event) - if abm: - await self.handle_msg(abm) + try: + abm = await self.convert_message(event) + if abm: + await self.handle_msg(abm) + except Exception as e: + logger.exception(f"Handle notice message failed: {e}") + return @self.bot.on_message("group") async def group(event: Event): - abm = await self.convert_message(event) - if abm: - await self.handle_msg(abm) + try: + abm = await self.convert_message(event) + if abm: + await self.handle_msg(abm) + except Exception as e: + logger.exception(f"Handle group message failed: {e}") + return @self.bot.on_message("private") async def private(event: Event): - abm = await self.convert_message(event) - if abm: - await self.handle_msg(abm) + try: + abm = await self.convert_message(event) + if abm: + await self.handle_msg(abm) + except Exception as e: + logger.exception(f"Handle private message failed: {e}") + return @self.bot.on_websocket_connection def on_websocket_connection(_): @@ -372,9 +389,10 @@ class AiocqhttpAdapter(Platform): 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 + for m in m_group: + 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: try: