Towncrier build

This commit is contained in:
Alex Root Junior 2023-02-19 18:10:11 +02:00
parent 7efec4a5df
commit 46218b8696
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
4 changed files with 60 additions and 19 deletions

View file

@ -19,6 +19,35 @@ Changelog
3.0.0b7 (2023-02-18) 3.0.0b7 (2023-02-18)
===================== =====================
.. warning::
Note that this version has incompatibility with Python 3.8-3.10 in case when you create an instance of Dispatcher outside of the any coroutine.
Sorry for the inconvenience, it will be fixed in the next version.
This code will not work:
.. code-block:: python
dp = Dispatcher()
def main():
dp.run_polling()
main()
But if you change it like this it should works as well:
.. code-block:: python
router = Router()
async def main():
dp = Dispatcher()
dp.include_router(router)
asyncio.run(main())
Features Features
-------- --------

View file

@ -119,4 +119,4 @@ prepare-release: bump towncrier-build
release: release:
git add . git add .
git commit -m "Release $(shell poetry version -s)" git commit -m "Release $(shell poetry version -s)"
git tag v$(shell poetry version -s) git tag v$(shell hatch version -s)

View file

@ -1,16 +1,18 @@
import asyncio
import logging import logging
from aiogram import Bot, Dispatcher, types from aiogram import Bot, Dispatcher, Router, types
from aiogram.filters import Command from aiogram.filters import Command
from aiogram.types import Message from aiogram.types import Message
# Bot token can be obtained via https://t.me/BotFahter
TOKEN = "42:TOKEN" TOKEN = "42:TOKEN"
dp = Dispatcher()
logger = logging.getLogger(__name__) # All handlers should be attached to the Router (or Dispatcher)
router = Router()
@dp.message(Command(commands=["start"])) @router.message(Command(commands=["start"]))
async def command_start_handler(message: Message) -> None: async def command_start_handler(message: Message) -> None:
""" """
This handler receive messages with `/start` command This handler receive messages with `/start` command
@ -23,7 +25,7 @@ async def command_start_handler(message: Message) -> None:
await message.answer(f"Hello, <b>{message.from_user.full_name}!</b>") await message.answer(f"Hello, <b>{message.from_user.full_name}!</b>")
@dp.message() @router.message()
async def echo_handler(message: types.Message) -> None: async def echo_handler(message: types.Message) -> None:
""" """
Handler will forward received message back to the sender Handler will forward received message back to the sender
@ -38,12 +40,18 @@ async def echo_handler(message: types.Message) -> None:
await message.answer("Nice try!") await message.answer("Nice try!")
def main() -> None: async def main() -> None:
# Initialize Bot instance with an default parse mode which will be passed to all API calls # 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="HTML") bot = Bot(TOKEN, parse_mode="HTML")
# And the run events dispatching # And the run events dispatching
dp.run_polling(bot) await dp.start_polling(bot)
if __name__ == "__main__": if __name__ == "__main__":
main() logging.basicConfig(level=logging.INFO)
asyncio.run(main())

View file

@ -1,3 +1,4 @@
import asyncio
import logging import logging
from aiogram import Bot, Dispatcher, Router from aiogram import Bot, Dispatcher, Router
@ -11,13 +12,14 @@ from aiogram.types import (
) )
TOKEN = "6wo" TOKEN = "6wo"
dp = Dispatcher()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
router = Router()
@dp.message(Command(commands=["start"]))
@router.message(Command(commands=["start"]))
async def command_start_handler(message: Message) -> None: async def command_start_handler(message: Message) -> None:
""" """
This handler receive messages with `/start` command This handler receive messages with `/start` command
@ -31,7 +33,7 @@ async def command_start_handler(message: Message) -> None:
) )
@dp.chat_member() @router.chat_member()
async def chat_member_update(chat_member: ChatMemberUpdated, bot: Bot) -> None: async def chat_member_update(chat_member: ChatMemberUpdated, bot: Bot) -> None:
await bot.send_message( await bot.send_message(
chat_member.chat.id, chat_member.chat.id,
@ -71,20 +73,22 @@ async def my_chat_member_change(chat_member: ChatMemberUpdated, bot: Bot) -> Non
) )
def main() -> None: async def main() -> None:
# 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="HTML") bot = Bot(TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_router(router)
sub_router.include_router(deep_dark_router) sub_router.include_router(deep_dark_router)
router.include_router(sub_router)
dp.include_router(sub_router) router.include_router(sub_sub_router)
dp.include_router(sub_sub_router)
useful_updates = dp.resolve_used_update_types() useful_updates = dp.resolve_used_update_types()
# And the run events dispatching # And the run events dispatching
dp.run_polling(bot, allowed_updates=useful_updates) await dp.start_polling(bot, allowed_updates=useful_updates)
if __name__ == "__main__": if __name__ == "__main__":
main() logging.basicConfig(level=logging.INFO)
asyncio.run(main())