From 2ff7ca3025a5e7a454672e428d7ad51796c11fe0 Mon Sep 17 00:00:00 2001 From: fdc310 <82008029+fdc310@users.noreply.github.com> Date: Sun, 15 Jun 2025 17:22:35 +0800 Subject: [PATCH] feat:add file url and add onebotv11(napcat) send file and seve file in local. (#1533) * feat:add file url and add onebotv11(napcat) send file and seve file in local. * del print --- pkg/platform/sources/aiocqhttp.py | 19 +++++++++++++++++++ pkg/platform/types/message.py | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/platform/sources/aiocqhttp.py b/pkg/platform/sources/aiocqhttp.py index 46c69041..71eac6f5 100644 --- a/pkg/platform/sources/aiocqhttp.py +++ b/pkg/platform/sources/aiocqhttp.py @@ -61,6 +61,9 @@ class AiocqhttpMessageConverter(adapter.MessageConverter): elif type(msg) is platform_message.Forward: for node in msg.node_list: msg_list.extend((await AiocqhttpMessageConverter.yiri2target(node.message_chain))[0]) + elif isinstance(msg, platform_message.File): + msg_list.append({"type":"file", "data":{'file': msg.url, "name": msg.name}}) + else: msg_list.append(aiocqhttp.MessageSegment.text(str(msg))) @@ -69,6 +72,7 @@ class AiocqhttpMessageConverter(adapter.MessageConverter): @staticmethod async def target2yiri(message: str, message_id: int = -1,bot=None): + # print(message) message = aiocqhttp.Message(message) async def process_message_data(msg_data, reply_list): @@ -134,6 +138,18 @@ class AiocqhttpMessageConverter(adapter.MessageConverter): reply_msg = platform_message.Quote(message_id=msg.data["id"],sender_id=msg_datas["user_id"],origin=reply_list) yiri_msg_list.append(reply_msg) + elif msg.type == 'file': + # file_name = msg.data['file'] + file_id = msg.data['file_id'] + file_data = await bot.get_file(file_id=file_id) + file_name = file_data.get('file_name') + file_path = file_data.get('file') + file_url = file_data.get('file_url') + file_size = file_data.get('file_size') + yiri_msg_list.append(platform_message.File(id=file_id, name=file_name,url=file_url,size=file_size)) + + + @@ -154,9 +170,11 @@ class AiocqhttpEventConverter(adapter.EventConverter): @staticmethod async def target2yiri(event: aiocqhttp.Event,bot=None): + yiri_chain = await AiocqhttpMessageConverter.target2yiri(event.message, event.message_id,bot) + if event.message_type == 'group': permission = 'MEMBER' @@ -235,6 +253,7 @@ class AiocqhttpAdapter(adapter.MessagePlatformAdapter): aiocq_msg = (await AiocqhttpMessageConverter.yiri2target(message))[0] if target_type == 'group': + await self.bot.send_group_msg(group_id=int(target_id), message=aiocq_msg) elif target_type == 'person': await self.bot.send_private_msg(user_id=int(target_id), message=aiocq_msg) diff --git a/pkg/platform/types/message.py b/pkg/platform/types/message.py index 88251cd1..94756149 100644 --- a/pkg/platform/types/message.py +++ b/pkg/platform/types/message.py @@ -800,12 +800,14 @@ class File(MessageComponent): type: str = 'File' """消息组件类型。""" - id: str + id: str = '' """文件识别 ID。""" name: str """文件名称。""" - size: int + size: int = '' """文件大小。""" + url: str + """文件路径""" def __str__(self): return f'[文件]{self.name}'