Skip to content

Commit 31741d1

Browse files
committed
refactor: 修复处理kook消息失败时打印消息类型是数字而不是类型名称的bug,_parse_card_message验证数据模型失败后改为直接raise
1 parent b64a0d6 commit 31741d1

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

astrbot/core/platform/sources/kook/kook_adapter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@ def _parse_card_message(self, data: KookMessageEvent) -> tuple[list, str]:
273273
try:
274274
card_list = KookCardMessageContainer.from_dict(json.loads(content))
275275

276-
except pydantic.ValidationError as e:
277-
logger.error(f"[KOOK] 解析卡片消息错误: {e}")
278-
logger.error(f"[KOOK] 原始消息内容: {data.to_json()}")
276+
except pydantic.ValidationError:
277+
raise
279278

280279
text_parts: list[str] = []
281280
images: list[str] = []
@@ -370,10 +369,11 @@ async def convert_message(self, data: KookMessageEvent) -> AstrBotMessage:
370369
abm.message, abm.message_str = self._parse_card_message(data)
371370
except Exception as exp:
372371
logger.error(f"[KOOK] 卡片消息解析失败: {exp}")
372+
logger.error(f"[KOOK] 原始消息内容: {data.to_json()}")
373373
abm.message_str = "[卡片消息解析失败]"
374374
abm.message = [Plain(text="[卡片消息解析失败]")]
375375
else:
376-
logger.warning(f'[KOOK] 不支持的kook消息类型: "{data.type}"')
376+
logger.warning(f'[KOOK] 不支持的kook消息类型: "{data.type.name}"')
377377
abm.message_str = "[不支持的消息类型]"
378378
abm.message = [Plain(text="[不支持的消息类型]")]
379379

astrbot/core/platform/sources/kook/kook_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async def send(self, message: MessageChain):
183183
if item.reply_id:
184184
reply_id = item.reply_id
185185
if not item.text:
186-
logger.debug(f'[Kook] 跳过空消息,类型为"{item.type}"')
186+
logger.debug(f'[Kook] 跳过空消息,类型为"{item.type.name}"')
187187
continue
188188
try:
189189
await self.client.send_text(

0 commit comments

Comments
 (0)