Merge pull request #728 from RockChinQ/feat/active-message

Feat: aiocqhttp 和 qq-botpy 适配器的主动消息发送接口
This commit is contained in:
Junyan Qin 2024-03-16 15:18:27 +08:00 committed by GitHub
commit 98bebfddaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 10 deletions

View File

@ -40,7 +40,6 @@ class AiocqhttpMessageConverter(adapter.MessageConverter):
elif type(msg) is mirai.Voice:
msg_list.append(aiocqhttp.MessageSegment.record(msg.path))
elif type(msg) is forward.Forward:
# print("aiocqhttp 暂不支持转发消息组件的转换,使用普通消息链发送")
for node in msg.node_list:
msg_list.extend(AiocqhttpMessageConverter.yiri2target(node.message_chain)[0])
@ -225,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,
@ -234,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(