mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
feat: aiocqhttp和qq-botpy的主动消息发送接口
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user