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

56 lines
1.3 KiB
Python
Raw Normal View History

class BaseMiddleware:
"""
Base class for middleware.
Your middlewares should be inherited from this class.
"""
def __init__(self):
pass
async def pre_process(self, message, data):
raise NotImplementedError
async def post_process(self, message, data, exception):
raise NotImplementedError
2022-02-19 21:37:03 +03:00
2022-01-24 20:24:56 +03:00
class State:
def __init__(self) -> None:
self.name = None
2022-02-19 21:37:03 +03:00
2022-01-24 20:24:56 +03:00
def __str__(self) -> str:
return self.name
2022-02-19 21:37:03 +03:00
2022-01-24 20:24:56 +03:00
class StatesGroup:
def __init_subclass__(cls) -> None:
2022-03-07 15:31:02 +03:00
2022-01-24 20:24:56 +03:00
for name, value in cls.__dict__.items():
if not name.startswith('__') and not callable(value) and isinstance(value, State):
# change value of that variable
2022-03-06 22:18:11 +03:00
value.name = ':'.join((cls.__name__, name))
class SkipHandler:
"""
Class for skipping handlers.
Just return instance of this class
in middleware to skip handler.
Update will go to post_process,
but will skip execution of handler.
"""
def __init__(self) -> None:
pass
class CancelUpdate:
"""
Class for canceling updates.
Just return instance of this class
in middleware to skip update.
Update will skip handler and execution
of post_process in middlewares.
"""
def __init__(self) -> None:
pass