Small cleanup in examples

This commit is contained in:
Alex Root Junior 2023-08-21 01:13:19 +03:00
parent 787ad6b094
commit b7be9c2b81
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
3 changed files with 6 additions and 20 deletions

View file

@ -13,10 +13,10 @@ from aiogram.utils.markdown import hbold
TOKEN = getenv("BOT_TOKEN") TOKEN = getenv("BOT_TOKEN")
# All handlers should be attached to the Router (or Dispatcher) # 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: async def command_start_handler(message: Message) -> None:
""" """
This handler receives messages with `/start` command 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)}!") await message.answer(f"Hello, {hbold(message.from_user.full_name)}!")
@router.message() @dp.message()
async def echo_handler(message: types.Message) -> None: async def echo_handler(message: types.Message) -> None:
""" """
Handler will forward receive a message back to the sender 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: 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 # Initialize Bot instance with a default parse mode which will be passed to all API calls
bot = Bot(TOKEN, parse_mode=ParseMode.HTML) bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
# And the run events dispatching # And the run events dispatching
@ -58,7 +53,4 @@ async def main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout) logging.basicConfig(level=logging.INFO, stream=sys.stdout)
try:
asyncio.run(main()) asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logging.info("Bot stopped!")

View file

@ -133,7 +133,4 @@ async def main():
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout) logging.basicConfig(level=logging.INFO, stream=sys.stdout)
try:
asyncio.run(main()) asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logging.info("Bot stopped!")

View file

@ -93,7 +93,4 @@ async def main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout) logging.basicConfig(level=logging.INFO, stream=sys.stdout)
try:
asyncio.run(main()) asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.info("Bot stopped!")