From 7e1e51c450bfe5bcc0d86873eb36e0bb3a381251 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Fri, 21 Apr 2023 01:00:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20QQ=E6=94=AF=E6=8C=81at=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=96=B9=E5=92=8C=E7=94=BB=E7=94=BB=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 6 +++++- model/platform/qq.py | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index a4ea833cd..79ceff7f9 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -362,7 +362,11 @@ def send_message(platform, message, res, msg_ref = None, image = None, gocq_loop qqchannel_bot.send_qq_msg(message, res, image_mode=True, msg_ref=msg_ref) else: qqchannel_bot.send_qq_msg(message, res, msg_ref=msg_ref) - if platform == PLATFORM_GOCQ: asyncio.run_coroutine_threadsafe(gocq_bot.send_qq_msg(message, res), gocq_loop).result() + if platform == PLATFORM_GOCQ: + if image != None: + asyncio.run_coroutine_threadsafe(gocq_bot.send_qq_msg(message, image, image_mode=True), gocq_loop).result() + else: + asyncio.run_coroutine_threadsafe(gocq_bot.send_qq_msg(message, res), gocq_loop).result() ''' 处理消息 diff --git a/model/platform/qq.py b/model/platform/qq.py index 90de07c5f..fc321c2b6 100644 --- a/model/platform/qq.py +++ b/model/platform/qq.py @@ -1,18 +1,31 @@ -from nakuru.entities.components import Plain +from nakuru.entities.components import Plain, At, Image class QQ: def run_bot(self, gocq): self.client = gocq self.client.run() - async def send_qq_msg(self, source, res): + async def send_qq_msg(self, source, res, image_mode = False): print("[System-Info] 回复QQ消息中..."+res) # 通过消息链处理 - if source.type == "GroupMessage": - await self.client.sendGroupMessage(source.group_id, [ - Plain(text=res) - ]) - elif source.type == "FriendMessage": - await self.client.sendFriendMessage(source.user_id, [ - Plain(text=res) - ]) \ No newline at end of file + if not image_mode: + if source.type == "GroupMessage": + await self.client.sendGroupMessage(source.group_id, [ + At(target=source.user_id), + Plain(text=res) + ]) + elif source.type == "FriendMessage": + await self.client.sendFriendMessage(source.user_id, [ + Plain(text=res) + ]) + else: + if source.type == "GroupMessage": + await self.client.sendGroupMessage(source.group_id, [ + At(target=source.user_id), + Plain(text="好的,我根据你的需要为你生成了一张图片😊") + Image.fromURL(url=res) + ]) + elif source.type == "FriendMessage": + await self.client.sendFriendMessage(source.user_id, [ + Image.fromURL(url=res) + ]) \ No newline at end of file