From 82d845b5c8c5efd0d8ffe116153d61f5c6c1d2f1 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 16 Jan 2023 19:15:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=97=B6=E7=9A=84=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/plugin/host.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/host.py b/pkg/plugin/host.py index 1f60313e..598512aa 100644 --- a/pkg/plugin/host.py +++ b/pkg/plugin/host.py @@ -166,7 +166,12 @@ class PluginHost: context.set_plugin_host(self) def get_runtime_context(self) -> context: - """获取运行时上下文""" + """获取运行时上下文(pkg.utils.context模块的对象) + + 此上下文用于和主程序其他模块交互(数据库、QQ机器人、OpenAI接口等) + 详见pkg.utils.context模块 + 其中的context变量保存了其他重要模块的类对象,可以使用这些对象进行交互 + """ return context def get_bot(self) -> Mirai: @@ -192,12 +197,14 @@ class PluginHost: for plugin in __plugins__.values(): for hook in plugin['hooks'].get(event_name, []): try: + already_prevented_default = event_context.is_prevented_default() + kwargs['host'] = context.get_plugin_host() kwargs['event'] = event_context hook(plugin['instance'], **kwargs) - if event_context.is_prevented_default(): + if event_context.is_prevented_default() and not already_prevented_default: logging.debug("插件 {} 已要求阻止事件 {} 的默认行为".format(plugin['name'], event_name)) if event_context.is_prevented_postorder():