From dab20e31874d555118f74b58512ab1c09d82e2a3 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Sat, 16 Mar 2024 15:16:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20aiocqhttp=E5=92=8Cqq-botpy=E7=9A=84?= =?UTF-8?q?=E4=B8=BB=E5=8A=A8=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/aiocqhttp.py | 11 +++++++---- pkg/platform/sources/qqbotpy.py | 28 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pkg/platform/sources/aiocqhttp.py b/pkg/platform/sources/aiocqhttp.py index 85a78fcd..f17a2016 100644 --- a/pkg/platform/sources/aiocqhttp.py +++ b/pkg/platform/sources/aiocqhttp.py @@ -224,16 +224,19 @@ class AiocqhttpAdapter(adapter.MessageSourceAdapter): async def send_message( self, target_type: str, target_id: str, message: mirai.MessageChain ): - # TODO 实现发送消息 - return super().send_message(target_type, target_id, message) + aiocq_msg = 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) async def reply_message( self, message_source: mirai.MessageEvent, message: mirai.MessageChain, quote_origin: bool = False, - ): - + ): aiocq_event = AiocqhttpEventConverter.yiri2target(message_source, self.bot_account_id) aiocq_msg = AiocqhttpMessageConverter.yiri2target(message)[0] if quote_origin: diff --git a/pkg/platform/sources/qqbotpy.py b/pkg/platform/sources/qqbotpy.py index 20190c60..ab981cfe 100644 --- a/pkg/platform/sources/qqbotpy.py +++ b/pkg/platform/sources/qqbotpy.py @@ -387,7 +387,28 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter): async def send_message( self, target_type: str, target_id: str, message: mirai.MessageChain ): - pass + message_list = self.message_converter.yiri2target(message) + + for msg in message_list: + args = {} + + if msg["type"] == "text": + args["content"] = msg["content"] + elif msg["type"] == "image": + args["image"] = msg["content"] + elif msg["type"] == "file_image": + args["file_image"] = msg["content"] + else: + continue + + if target_type == "group": + args["channel_id"] = str(target_id) + + await self.bot.api.post_message(**args) + elif target_type == "person": + args["guild_id"] = str(target_id) + + await self.bot.api.post_dms(**args) async def reply_message( self, @@ -395,8 +416,8 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter): message: mirai.MessageChain, quote_origin: bool = False, ): + message_list = self.message_converter.yiri2target(message) - tasks = [] msg_seq = 1 @@ -432,9 +453,6 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter): ] await self.bot.api.post_dms(**args) elif type(message_source) == OfficialGroupMessage: - # args['guild_id'] = str(message_source.sender.group.id) - # args['msg_id'] = cached_message_ids[str(message_source.message_chain.message_id)] - # await self.bot.api.post_message(**args) if "image" in args or "file_image" in args: continue args["group_openid"] = self.group_openid_mapping.getkey(