1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1635 from coder2020official/master

Fixed description
This commit is contained in:
Badiboy 2022-07-17 00:42:55 +03:00 committed by GitHub
commit 54ad1582aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2971,13 +2971,13 @@ class TeleBot:
def setup_middleware(self, middleware: BaseMiddleware): def setup_middleware(self, middleware: BaseMiddleware):
""" """
Register middleware Registers class-based middleware.
:param middleware: Subclass of `telebot.handler_backends.BaseMiddleware` :param middleware: Subclass of `telebot.handler_backends.BaseMiddleware`
:return: None :return: None
""" """
if not self.use_class_middlewares: if not self.use_class_middlewares:
logger.error('Middleware is not enabled. Pass use_class_middlewares=True to enable it.') logger.error('Class-based middlewares are not enabled. Pass use_class_middlewares=True to enable it.')
return return
if not hasattr(middleware, 'update_types'): if not hasattr(middleware, 'update_types'):
@ -3139,7 +3139,7 @@ class TeleBot:
def middleware_handler(self, update_types=None): def middleware_handler(self, update_types=None):
""" """
Middleware handler decorator. Function-based middleware handler decorator.
This decorator can be used to decorate functions that must be handled as middlewares before entering any other This decorator can be used to decorate functions that must be handled as middlewares before entering any other
message handlers message handlers
@ -3196,10 +3196,9 @@ class TeleBot:
# function register_middleware_handler # function register_middleware_handler
def register_middleware_handler(self, callback, update_types=None): def register_middleware_handler(self, callback, update_types=None):
""" """
Middleware handler decorator. Adds function-based middleware handler.
This function will create a decorator that can be used to decorate functions that must be handled as middlewares before entering any other This function will register your decorator function. Function-based middlewares are executed before handlers.
message handlers
But, be careful and check type of the update inside the handler if more than one update_type is given But, be careful and check type of the update inside the handler if more than one update_type is given
Example: Example:
@ -4115,6 +4114,7 @@ class TeleBot:
if self.exception_handler: if self.exception_handler:
self.exception_handler.handle(e) self.exception_handler.handle(e)
else: logging.error(str(e)) else: logging.error(str(e))
if middlewares: if middlewares:
for middleware in middlewares: for middleware in middlewares: