From cc675a9b4f5de6c878068e0267d4b5b1663e6435 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 28 Sep 2023 20:12:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AF=B9=E6=8F=92=E4=BB=B6=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E6=9B=B4=E5=A4=9A=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 2 +- model/platform/qq.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 89e1fb5d..b568e132 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -679,7 +679,7 @@ def oper_msg(message, if hit: # 检查指令. command_result是一个元组:(指令调用是否成功, 指令返回的文本结果, 指令类型) if command_result == None: - send_message(platform, message, "指令调用未返回任何信息。", msg_ref=msg_ref, session_id=session_id) + # send_message(platform, message, "指令调用未返回任何信息。", msg_ref=msg_ref, session_id=session_id) return command = command_result[2] if command == "keyword": diff --git a/model/platform/qq.py b/model/platform/qq.py index 016cdbe1..0b37583d 100644 --- a/model/platform/qq.py +++ b/model/platform/qq.py @@ -37,7 +37,8 @@ class QQ: async def send_qq_msg(self, source, - res): + res, + image_mode=None): self.gocq_cnt += 1 if not self.is_start: raise Exception("管理员未启动GOCQ平台") @@ -59,7 +60,8 @@ class QQ: res.append(Plain(text=res_str)) # if image mode, put all Plain texts into a new picture. - image_mode = self.cc.get('qq_pic_mode', False) + if image_mode is None: + image_mode = self.cc.get('qq_pic_mode', False) if image_mode and isinstance(res, list): plains = [] news = [] @@ -111,13 +113,15 @@ class QQ: def send(self, to, res, + image_mode=False, ): ''' 提供给插件的发送QQ消息接口, 不用在外部await。 参数说明:第一个参数可以是消息对象,也可以是QQ群号。第二个参数是消息内容(消息内容可以是消息链列表,也可以是纯文字信息)。 + 第三个参数是是否开启图片模式,如果开启,那么所有纯文字信息都会被合并成一张图片。 ''' try: - asyncio.run_coroutine_threadsafe(self.send_qq_msg(to, res), self.gocq_loop).result() + asyncio.run_coroutine_threadsafe(self.send_qq_msg(to, res, image_mode), self.gocq_loop).result() except BaseException as e: raise e @@ -163,3 +167,17 @@ class QQ: del self.waiting[group_id] return ret time.sleep(0.5) + + def get_client(self): + return self.client + + def nakuru_method_invoker(self, func, *args, **kwargs): + """ + 返回一个方法调用器,可以用来立即调用nakuru的方法。 + """ + try: + ret = asyncio.run_coroutine_threadsafe(func(*args, **kwargs), self.gocq_loop).result() + return ret + except BaseException as e: + raise e +