mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-10 17:53:17 +00:00
More comments in FSM example.
This commit is contained in:
parent
5953ba5426
commit
5f6af637e8
1 changed files with 8 additions and 0 deletions
|
|
@ -9,7 +9,10 @@ from aiogram.utils.markdown import text, bold
|
||||||
API_TOKEN = 'BOT TOKEN HERE'
|
API_TOKEN = 'BOT TOKEN HERE'
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
bot = Bot(token=API_TOKEN, loop=loop)
|
bot = Bot(token=API_TOKEN, loop=loop)
|
||||||
|
|
||||||
|
# For example use simple MemoryStorage for Dispatcher.
|
||||||
storage = MemoryStorage()
|
storage = MemoryStorage()
|
||||||
dp = Dispatcher(bot, storage=storage)
|
dp = Dispatcher(bot, storage=storage)
|
||||||
|
|
||||||
|
|
@ -40,8 +43,12 @@ async def cancel_handler(message: types.Message):
|
||||||
Allow to cancel any action
|
Allow to cancel any action
|
||||||
"""
|
"""
|
||||||
with dp.current_state(chat=message.chat.id, user=message.from_user.id) as state:
|
with dp.current_state(chat=message.chat.id, user=message.from_user.id) as state:
|
||||||
|
# Ignore command is user is not in any (defined) state
|
||||||
if await state.get_state() is None:
|
if await state.get_state() is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Otherwise cancel state and inform user about that.
|
||||||
|
# And just in case remove keyboard.
|
||||||
await state.reset_state(with_data=True)
|
await state.reset_state(with_data=True)
|
||||||
await message.reply('Canceled.', reply_markup=types.ReplyKeyboardRemove())
|
await message.reply('Canceled.', reply_markup=types.ReplyKeyboardRemove())
|
||||||
|
|
||||||
|
|
@ -117,6 +124,7 @@ async def main():
|
||||||
# Skip old updates
|
# Skip old updates
|
||||||
count = await dp.skip_updates()
|
count = await dp.skip_updates()
|
||||||
print(f"Skipped {count} updates.")
|
print(f"Skipped {count} updates.")
|
||||||
|
|
||||||
await dp.start_pooling()
|
await dp.start_pooling()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue