From b7be9c2b81c2f4312634d2e1173c8a1c04f8dbb4 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 21 Aug 2023 01:13:19 +0300 Subject: [PATCH] Small cleanup in examples --- examples/echo_bot.py | 16 ++++------------ examples/finite_state_machine.py | 5 +---- examples/specify_updates.py | 5 +---- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/echo_bot.py b/examples/echo_bot.py index fc0bb0ff..7cb1babe 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -13,10 +13,10 @@ from aiogram.utils.markdown import hbold TOKEN = getenv("BOT_TOKEN") # All handlers should be attached to the Router (or Dispatcher) -router = Router() +dp = Dispatcher() -@router.message(CommandStart()) +@dp.message(CommandStart()) async def command_start_handler(message: Message) -> None: """ This handler receives messages with `/start` command @@ -29,7 +29,7 @@ async def command_start_handler(message: Message) -> None: await message.answer(f"Hello, {hbold(message.from_user.full_name)}!") -@router.message() +@dp.message() async def echo_handler(message: types.Message) -> None: """ Handler will forward receive a message back to the sender @@ -45,11 +45,6 @@ async def echo_handler(message: types.Message) -> None: async def main() -> None: - # Dispatcher is a root router - dp = Dispatcher() - # ... and all other routers should be attached to Dispatcher - dp.include_router(router) - # Initialize Bot instance with a default parse mode which will be passed to all API calls bot = Bot(TOKEN, parse_mode=ParseMode.HTML) # And the run events dispatching @@ -58,7 +53,4 @@ async def main() -> None: if __name__ == "__main__": logging.basicConfig(level=logging.INFO, stream=sys.stdout) - try: - asyncio.run(main()) - except (KeyboardInterrupt, SystemExit): - logging.info("Bot stopped!") + asyncio.run(main()) diff --git a/examples/finite_state_machine.py b/examples/finite_state_machine.py index 260fdfdf..2905ec5b 100644 --- a/examples/finite_state_machine.py +++ b/examples/finite_state_machine.py @@ -133,7 +133,4 @@ async def main(): if __name__ == "__main__": logging.basicConfig(level=logging.INFO, stream=sys.stdout) - try: - asyncio.run(main()) - except (KeyboardInterrupt, SystemExit): - logging.info("Bot stopped!") + asyncio.run(main()) diff --git a/examples/specify_updates.py b/examples/specify_updates.py index ead296ea..56571f1a 100644 --- a/examples/specify_updates.py +++ b/examples/specify_updates.py @@ -93,7 +93,4 @@ async def main() -> None: if __name__ == "__main__": logging.basicConfig(level=logging.INFO, stream=sys.stdout) - try: - asyncio.run(main()) - except (KeyboardInterrupt, SystemExit): - logger.info("Bot stopped!") + asyncio.run(main())