feat: aiocqhttp和qq-botpy的主动消息发送接口

This commit is contained in:
RockChinQ
2024-03-16 15:16:46 +08:00
parent 09e72f7c5f
commit dab20e3187
2 changed files with 30 additions and 9 deletions

View File

@@ -224,8 +224,12 @@ 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,
@@ -233,7 +237,6 @@ class AiocqhttpAdapter(adapter.MessageSourceAdapter):
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:

View File

@@ -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(