Merge branch 'aiogram:dev-3.x' into dev-3.x

This commit is contained in:
Łukasz Tshipenchko 2023-04-02 23:24:43 +06:00 committed by GitHub
commit 2d9f07e619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
907 changed files with 16631 additions and 17310 deletions

View file

@ -1,16 +1,18 @@
import asyncio
import logging
from aiogram import Bot, Dispatcher, types
from aiogram import Bot, Dispatcher, Router, types
from aiogram.filters import Command
from aiogram.types import Message
# Bot token can be obtained via https://t.me/BotFahter
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:
"""
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>")
@dp.message()
@router.message()
async def echo_handler(message: types.Message) -> None:
"""
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!")
def main() -> None:
# Initialize Bot instance with an default parse mode which will be passed to all API calls
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="HTML")
# And the run events dispatching
dp.run_polling(bot)
await dp.start_polling(bot)
if __name__ == "__main__":
main()
logging.basicConfig(level=logging.INFO)
asyncio.run(main())

View file

@ -8,7 +8,12 @@ from aiogram import Bot, Dispatcher, F, Router, html
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import KeyboardButton, Message, ReplyKeyboardMarkup, ReplyKeyboardRemove
from aiogram.types import (
KeyboardButton,
Message,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
)
form_router = Router()
@ -19,7 +24,7 @@ class Form(StatesGroup):
language = State()
@form_router.message(Command(commands=["start"]))
@form_router.message(Command("start"))
async def command_start(message: Message, state: FSMContext) -> None:
await state.set_state(Form.name)
await message.answer(
@ -28,7 +33,7 @@ async def command_start(message: Message, state: FSMContext) -> None:
)
@form_router.message(Command(commands=["cancel"]))
@form_router.message(Command("cancel"))
@form_router.message(F.text.casefold() == "cancel")
async def cancel_handler(message: Message, state: FSMContext) -> None:
"""

View file

@ -48,7 +48,7 @@ async def command_add_bot(message: Message, command: CommandObject, bot: Bot) ->
return message.answer("Invalid token")
await new_bot.delete_webhook(drop_pending_updates=True)
await new_bot.set_webhook(OTHER_BOTS_URL.format(bot_token=command.args))
await message.answer(f"Bot @{bot_user.username} successful added")
return await message.answer(f"Bot @{bot_user.username} successful added")
async def on_startup(dispatcher: Dispatcher, bot: Bot):

View file

@ -1,3 +1,4 @@
import asyncio
import logging
from aiogram import Bot, Dispatcher, Router
@ -11,13 +12,14 @@ from aiogram.types import (
)
TOKEN = "6wo"
dp = Dispatcher()
logger = logging.getLogger(__name__)
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:
"""
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:
await bot.send_message(
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
bot = Bot(TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_router(router)
sub_router.include_router(deep_dark_router)
dp.include_router(sub_router)
dp.include_router(sub_sub_router)
router.include_router(sub_router)
router.include_router(sub_sub_router)
useful_updates = dp.resolve_used_update_types()
# 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__":
main()
logging.basicConfig(level=logging.INFO)
asyncio.run(main())

View file

@ -36,7 +36,6 @@ async def send_message_handler(request: Request):
except ValueError:
return json_response({"ok": False, "err": "Unauthorized"}, status=401)
print(data)
reply_markup = None
if data["with_webview"] == "1":
reply_markup = InlineKeyboardMarkup(