diff --git a/src/plugins/built_in/napcat_adapter_plugin/plugin.py b/src/plugins/built_in/napcat_adapter_plugin/plugin.py index 952fcaccc..e15e17b8f 100644 --- a/src/plugins/built_in/napcat_adapter_plugin/plugin.py +++ b/src/plugins/built_in/napcat_adapter_plugin/plugin.py @@ -64,9 +64,15 @@ async def message_recv(server_connection: Server.ServerConnection): # 处理完整消息(可能是重组后的,也可能是原本就完整的) post_type = decoded_raw_message.get("post_type") + + # 兼容没有 post_type 的普通消息 + if not post_type and "message_type" in decoded_raw_message: + decoded_raw_message["post_type"] = "message" + post_type = "message" + if post_type in ["meta_event", "message", "notice"]: await message_queue.put(decoded_raw_message) - elif post_type is None: + else: await put_response(decoded_raw_message) except json.JSONDecodeError as e: diff --git a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py index 0a644345b..f289af687 100644 --- a/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py +++ b/src/plugins/built_in/napcat_adapter_plugin/src/recv_handler/message_handler.py @@ -859,6 +859,43 @@ class MessageHandler: data=f"这是一条小程序分享消息,可以根据来源,考虑使用对应解析工具\n{formatted_content}", ) + # 检查是否是音乐分享 + elif nested_data.get("view") == "music" and "music" in nested_data.get("meta", {}): + logger.debug("检测到音乐分享消息,开始提取信息") + music_info = nested_data["meta"]["music"] + title = music_info.get("title", "未知歌曲") + desc = music_info.get("desc", "未知艺术家") + jump_url = music_info.get("jumpUrl", "") + preview_url = music_info.get("preview", "") + source = music_info.get("tag", "未知来源") + + # 优化文本结构,使其更像卡片 + text_parts = [ + "--- 音乐分享 ---", + f"歌曲:{title}", + f"歌手:{desc}", + f"来源:{source}" + ] + if jump_url: + text_parts.append(f"链接:{jump_url}") + text_parts.append("----------------") + + text_content = "\n".join(text_parts) + + # 如果有预览图,创建一个seglist包含文本和图片 + if preview_url: + try: + image_base64 = await get_image_base64(preview_url) + if image_base64: + return Seg(type="seglist", data=[ + Seg(type="text", data=text_content + "\n"), + Seg(type="image", data=image_base64) + ]) + except Exception as e: + logger.error(f"下载音乐预览图失败: {e}") + + return Seg(type="text", data=text_content) + # 如果没有提取到关键信息,返回None return None