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

asyncio_middlewares.py was created && BaseMiddleware class was replaced to asyncio_middlewares.py

This commit is contained in:
abdullaev388 2022-02-19 16:02:14 +05:00
parent ae5d183db0
commit 5337d4838d
4 changed files with 18 additions and 17 deletions

View File

@ -1,6 +1,6 @@
# Just a little example of middleware handlers
from telebot.asyncio_handler_backends import BaseMiddleware
from telebot.asyncio_middlewares import BaseMiddleware
from telebot.async_telebot import AsyncTeleBot
from telebot.async_telebot import CancelUpdate
bot = AsyncTeleBot('TOKEN')

View File

@ -7,6 +7,7 @@
# But this example just to show the work of middlewares.
import telebot
import telebot.asyncio_middlewares
from telebot.async_telebot import AsyncTeleBot
from telebot import asyncio_handler_backends
import logging
@ -27,7 +28,7 @@ TRANSLATIONS = {
bot = AsyncTeleBot('TOKEN')
class LanguageMiddleware(asyncio_handler_backends.BaseMiddleware):
class LanguageMiddleware(telebot.asyncio_middlewares.BaseMiddleware):
def __init__(self):
self.update_types = ['message'] # Update types that will be handled by this middleware.
async def pre_process(self, message, data):

View File

@ -1,18 +1,3 @@
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
class State:
def __init__(self) -> None:
self.name = None

View File

@ -0,0 +1,15 @@
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