Add special handler for TypeHandler of install_plugins

This commit is contained in:
洛水居室 2022-11-29 20:05:16 +08:00
parent f19c9bd67a
commit 6b00edde7c
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -20,6 +20,7 @@ from telegram.ext import (
JobQueue, JobQueue,
MessageHandler, MessageHandler,
filters, filters,
TypeHandler,
) )
from telegram.ext.filters import StatusUpdate from telegram.ext.filters import StatusUpdate
@ -116,6 +117,10 @@ class Bot:
if hasattr(plugin, "__async_init__"): if hasattr(plugin, "__async_init__"):
await self.async_inject(plugin.__async_init__) await self.async_inject(plugin.__async_init__)
handlers = plugin.handlers 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) self.app.add_handlers(handlers)
if handlers: if handlers:
logger.debug(f'插件 "{path}" 添加了 {len(handlers)} 个 handler ') logger.debug(f'插件 "{path}" 添加了 {len(handlers)} 个 handler ')