Minor refactor examples/text_filter_example.py and examples/throtling_example.py

This commit is contained in:
Suren Khorenyan 2019-08-11 21:59:56 +03:00
parent 8538e6af57
commit 94811c57e1
2 changed files with 8 additions and 5 deletions

View file

@ -7,7 +7,8 @@ import logging
from aiogram import Bot, Dispatcher, executor, types from aiogram import Bot, Dispatcher, executor, types
API_TOKEN = 'API_TOKEN_HERE'
API_TOKEN = 'BOT_TOKEN_HERE'
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@ -16,10 +17,12 @@ logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN) bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot) dp = Dispatcher(bot)
# if the text from user in the list # if the text from user in the list
@dp.message_handler(text=['text1', 'text2']) @dp.message_handler(text=['text1', 'text2'])
async def text_in_handler(message: types.Message): async def text_in_handler(message: types.Message):
await message.answer("The message text is in the list!") await message.answer("The message text equals to one of in the list!")
# if the text contains any string # if the text contains any string
@dp.message_handler(text_contains='example1') @dp.message_handler(text_contains='example1')

View file

@ -4,7 +4,6 @@ Example for throttling manager.
You can use that for flood controlling. You can use that for flood controlling.
""" """
import asyncio
import logging import logging
from aiogram import Bot, types from aiogram import Bot, types
@ -13,14 +12,15 @@ from aiogram.dispatcher import Dispatcher
from aiogram.utils.exceptions import Throttled from aiogram.utils.exceptions import Throttled
from aiogram.utils.executor import start_polling from aiogram.utils.executor import start_polling
API_TOKEN = 'BOT TOKEN HERE'
API_TOKEN = 'BOT_TOKEN_HERE'
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN) bot = Bot(token=API_TOKEN)
# Throttling manager does not work without Leaky Bucket. # Throttling manager does not work without Leaky Bucket.
# Then need to use storages. For example use simple in-memory storage. # You need to use a storage. For example use simple in-memory storage.
storage = MemoryStorage() storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage) dp = Dispatcher(bot, storage=storage)