Добавлен пример с BaseFilter
This commit is contained in:
parent
338d9c4089
commit
01e9cdd2fd
@ -8,4 +8,5 @@
|
||||
- [Миддлварь в хендлерах](https://github.com/love-apples/maxapi/tree/main/examples/middleware_in_handlers/main.py)
|
||||
- [Вебхуки](https://github.com/love-apples/maxapi/tree/main/examples/webhook)
|
||||
- [Клавиатуры](https://github.com/love-apples/maxapi/tree/main/examples/keyboard/main.py)
|
||||
- [Миддлварь в роутерах](https://github.com/love-apples/maxapi/tree/main/examples/middleware_for_router/main.py)
|
||||
- [Миддлварь в роутерах](https://github.com/love-apples/maxapi/tree/main/examples/middleware_for_router/main.py)
|
||||
- [BaseFilter](https://github.com/love-apples/maxapi/tree/main/examples/base_filter/main.py)
|
38
examples/base_filter/main.py
Normal file
38
examples/base_filter/main.py
Normal file
@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from maxapi import Bot, Dispatcher
|
||||
from maxapi.types import MessageCreated, CommandStart, UpdateUnion
|
||||
from maxapi.filters import BaseFilter
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
bot = Bot(token='тут_ваш_токен')
|
||||
dp = Dispatcher()
|
||||
|
||||
|
||||
class FilterChat(BaseFilter):
|
||||
|
||||
"""
|
||||
Фильтр, который срабатывает только в чате с названием `Test`
|
||||
"""
|
||||
|
||||
async def __call__(self, event: UpdateUnion):
|
||||
|
||||
if not event.chat:
|
||||
return False
|
||||
|
||||
return event.chat == 'Test'
|
||||
|
||||
|
||||
@dp.message_created(CommandStart(), FilterChat())
|
||||
async def custom_data(event: MessageCreated):
|
||||
await event.message.answer('Привет!')
|
||||
|
||||
|
||||
async def main():
|
||||
await dp.start_polling(bot)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
Loading…
x
Reference in New Issue
Block a user