perf: 对插件开放更多接口

This commit is contained in:
Soulter
2023-09-28 20:12:39 +08:00
parent 08e7d4d0c6
commit cc675a9b4f
2 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -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":
+21 -3
View File
@@ -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