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:
parent
ae5d183db0
commit
5337d4838d
@ -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')
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
15
telebot/asyncio_middlewares.py
Normal file
15
telebot/asyncio_middlewares.py
Normal 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
|
Loading…
Reference in New Issue
Block a user