From 6b00edde7c2fb255d92ecee78177937ad4e660ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Tue, 29 Nov 2022 20:05:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E2=9C=A8=20Add=20special=20handler?= =?UTF-8?q?=20for=20`TypeHandler`=20of=20`install=5Fplugins`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/bot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/bot.py b/core/bot.py index 781426b..b6688ef 100644 --- a/core/bot.py +++ b/core/bot.py @@ -20,6 +20,7 @@ from telegram.ext import ( JobQueue, MessageHandler, filters, + TypeHandler, ) from telegram.ext.filters import StatusUpdate @@ -116,6 +117,10 @@ class Bot: if hasattr(plugin, "__async_init__"): await self.async_inject(plugin.__async_init__) handlers = plugin.handlers + for index, handler in enumerate(handlers): + if isinstance(handler, TypeHandler): # 对 TypeHandler 进行特殊处理,优先级必须设置 -1,否则无用 + handlers.pop(index) + self.app.add_handler(handler, group=-1) self.app.add_handlers(handlers) if handlers: logger.debug(f'插件 "{path}" 添加了 {len(handlers)} 个 handler ')