From f5684aef07ee91dcda1b9c851790ba2f0fc5fe41 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 14 Jun 2020 18:18:29 +0300 Subject: [PATCH] Update default parse_mode propagation. --- aiogram/api/client/bot.py | 6 +++++- aiogram/api/client/session/aiohttp.py | 10 +++++++--- aiogram/api/client/session/base.py | 17 +++++++++++++++-- aiogram/api/methods/add_sticker_to_set.py | 9 +++++++-- aiogram/api/methods/answer_callback_query.py | 9 +++++++-- aiogram/api/methods/answer_inline_query.py | 11 ++++++++--- .../api/methods/answer_pre_checkout_query.py | 9 +++++++-- aiogram/api/methods/answer_shipping_query.py | 9 +++++++-- aiogram/api/methods/base.py | 15 +++++---------- aiogram/api/methods/create_new_sticker_set.py | 9 +++++++-- aiogram/api/methods/delete_chat_photo.py | 9 +++++++-- aiogram/api/methods/delete_chat_sticker_set.py | 9 +++++++-- aiogram/api/methods/delete_message.py | 9 +++++++-- aiogram/api/methods/delete_sticker_from_set.py | 9 +++++++-- aiogram/api/methods/delete_webhook.py | 9 +++++++-- aiogram/api/methods/edit_message_caption.py | 11 ++++++++--- .../api/methods/edit_message_live_location.py | 9 +++++++-- aiogram/api/methods/edit_message_media.py | 11 ++++++++--- .../api/methods/edit_message_reply_markup.py | 9 +++++++-- aiogram/api/methods/edit_message_text.py | 9 +++++++-- aiogram/api/methods/export_chat_invite_link.py | 9 +++++++-- aiogram/api/methods/forward_message.py | 9 +++++++-- aiogram/api/methods/get_chat.py | 9 +++++++-- aiogram/api/methods/get_chat_administrators.py | 9 +++++++-- aiogram/api/methods/get_chat_member.py | 9 +++++++-- aiogram/api/methods/get_chat_members_count.py | 9 +++++++-- aiogram/api/methods/get_file.py | 9 +++++++-- aiogram/api/methods/get_game_high_scores.py | 9 +++++++-- aiogram/api/methods/get_me.py | 9 +++++++-- aiogram/api/methods/get_my_commands.py | 9 +++++++-- aiogram/api/methods/get_sticker_set.py | 9 +++++++-- aiogram/api/methods/get_updates.py | 9 +++++++-- aiogram/api/methods/get_user_profile_photos.py | 9 +++++++-- aiogram/api/methods/get_webhook_info.py | 9 +++++++-- aiogram/api/methods/kick_chat_member.py | 9 +++++++-- aiogram/api/methods/leave_chat.py | 9 +++++++-- aiogram/api/methods/pin_chat_message.py | 9 +++++++-- aiogram/api/methods/promote_chat_member.py | 9 +++++++-- aiogram/api/methods/restrict_chat_member.py | 9 +++++++-- aiogram/api/methods/send_animation.py | 9 +++++++-- aiogram/api/methods/send_audio.py | 9 +++++++-- aiogram/api/methods/send_chat_action.py | 9 +++++++-- aiogram/api/methods/send_contact.py | 9 +++++++-- aiogram/api/methods/send_dice.py | 9 +++++++-- aiogram/api/methods/send_document.py | 9 +++++++-- aiogram/api/methods/send_game.py | 9 +++++++-- aiogram/api/methods/send_invoice.py | 9 +++++++-- aiogram/api/methods/send_location.py | 9 +++++++-- aiogram/api/methods/send_media_group.py | 11 ++++++++--- aiogram/api/methods/send_message.py | 11 ++++++++--- aiogram/api/methods/send_photo.py | 9 +++++++-- aiogram/api/methods/send_poll.py | 11 ++++++++--- aiogram/api/methods/send_sticker.py | 9 +++++++-- aiogram/api/methods/send_venue.py | 9 +++++++-- aiogram/api/methods/send_video.py | 9 +++++++-- aiogram/api/methods/send_video_note.py | 9 +++++++-- aiogram/api/methods/send_voice.py | 9 +++++++-- .../set_chat_administrator_custom_title.py | 9 +++++++-- aiogram/api/methods/set_chat_description.py | 9 +++++++-- aiogram/api/methods/set_chat_permissions.py | 9 +++++++-- aiogram/api/methods/set_chat_photo.py | 9 +++++++-- aiogram/api/methods/set_chat_sticker_set.py | 9 +++++++-- aiogram/api/methods/set_chat_title.py | 9 +++++++-- aiogram/api/methods/set_game_score.py | 9 +++++++-- aiogram/api/methods/set_my_commands.py | 9 +++++++-- aiogram/api/methods/set_passport_data_errors.py | 9 +++++++-- .../api/methods/set_sticker_position_in_set.py | 9 +++++++-- aiogram/api/methods/set_sticker_set_thumb.py | 9 +++++++-- aiogram/api/methods/set_webhook.py | 9 +++++++-- .../api/methods/stop_message_live_location.py | 9 +++++++-- aiogram/api/methods/stop_poll.py | 9 +++++++-- aiogram/api/methods/unban_chat_member.py | 9 +++++++-- aiogram/api/methods/unpin_chat_message.py | 9 +++++++-- aiogram/api/methods/upload_sticker_file.py | 9 +++++++-- aiogram/dispatcher/dispatcher.py | 2 +- tests/mocked_bot.py | 4 ++-- tests/test_api/test_client/test_bot.py | 7 ++++--- .../test_session/test_aiohttp_session.py | 8 +++++--- .../test_methods/test_answer_inline_query.py | 13 +++++-------- tests/test_api/test_methods/test_base.py | 13 +++++++------ 80 files changed, 552 insertions(+), 185 deletions(-) diff --git a/aiogram/api/client/bot.py b/aiogram/api/client/bot.py index 50898e22..5a78e589 100644 --- a/aiogram/api/client/bot.py +++ b/aiogram/api/client/bot.py @@ -147,6 +147,10 @@ class Bot(ContextInstanceMixin["Bot"]): self.parse_mode = parse_mode self.__token = token + @property + def token(self) -> str: + return self.__token + @property def id(self) -> int: """ @@ -278,7 +282,7 @@ class Bot(ContextInstanceMixin["Bot"]): :param method: :return: """ - return await self.session.make_request(self.__token, method, timeout=request_timeout) + return await self.session.make_request(self, method, timeout=request_timeout) def __hash__(self) -> int: """ diff --git a/aiogram/api/client/session/aiohttp.py b/aiogram/api/client/session/aiohttp.py index 92adc896..53def8f2 100644 --- a/aiogram/api/client/session/aiohttp.py +++ b/aiogram/api/client/session/aiohttp.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import ( + TYPE_CHECKING, Any, AsyncGenerator, Dict, @@ -20,6 +21,9 @@ from aiogram.api.methods import Request, TelegramMethod from .base import BaseSession +if TYPE_CHECKING: + from ..bot import Bot + T = TypeVar("T") _ProxyBasic = Union[str, Tuple[str, BasicAuth]] _ProxyChain = Iterable[_ProxyBasic] @@ -126,12 +130,12 @@ class AiohttpSession(BaseSession): return form async def make_request( - self, token: str, call: TelegramMethod[T], timeout: Optional[int] = None + self, bot: Bot, call: TelegramMethod[T], timeout: Optional[int] = None ) -> T: session = await self.create_session() - request = call.build_request() - url = self.api.api_url(token=token, method=request.method) + request = call.build_request(bot) + url = self.api.api_url(token=bot.token, method=request.method) form = self.build_form_data(request) async with session.post( diff --git a/aiogram/api/client/session/base.py b/aiogram/api/client/session/base.py index c49d4b5a..69b534f7 100644 --- a/aiogram/api/client/session/base.py +++ b/aiogram/api/client/session/base.py @@ -4,7 +4,17 @@ import abc import datetime import json from types import TracebackType -from typing import Any, AsyncGenerator, Callable, ClassVar, Optional, Type, TypeVar, Union +from typing import ( + TYPE_CHECKING, + Any, + AsyncGenerator, + Callable, + ClassVar, + Optional, + Type, + TypeVar, + Union, +) from aiogram.utils.exceptions import TelegramAPIError @@ -13,6 +23,9 @@ from ...methods import Response, TelegramMethod from ...types import UNSET from ..telegram import PRODUCTION, TelegramAPIServer +if TYPE_CHECKING: + from ..bot import Bot + T = TypeVar("T") _JsonLoads = Callable[..., Any] _JsonDumps = Callable[..., str] @@ -37,7 +50,7 @@ class BaseSession(abc.ABC): @abc.abstractmethod async def make_request( - self, token: str, method: TelegramMethod[T], timeout: Optional[int] = UNSET + self, bot: Bot, method: TelegramMethod[T], timeout: Optional[int] = UNSET ) -> T: # pragma: no cover pass diff --git a/aiogram/api/methods/add_sticker_to_set.py b/aiogram/api/methods/add_sticker_to_set.py index f9c801e3..da4bcd12 100644 --- a/aiogram/api/methods/add_sticker_to_set.py +++ b/aiogram/api/methods/add_sticker_to_set.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InputFile, MaskPosition from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class AddStickerToSet(TelegramMethod[bool]): """ @@ -34,7 +39,7 @@ class AddStickerToSet(TelegramMethod[bool]): mask_position: Optional[MaskPosition] = None """A JSON-serialized object for position where the mask should be placed on faces""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"png_sticker", "tgs_sticker"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/answer_callback_query.py b/aiogram/api/methods/answer_callback_query.py index f0d8405f..0bbb9b3c 100644 --- a/aiogram/api/methods/answer_callback_query.py +++ b/aiogram/api/methods/answer_callback_query.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class AnswerCallbackQuery(TelegramMethod[bool]): """ @@ -33,7 +38,7 @@ class AnswerCallbackQuery(TelegramMethod[bool]): """The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="answerCallbackQuery", data=data) diff --git a/aiogram/api/methods/answer_inline_query.py b/aiogram/api/methods/answer_inline_query.py index eb8a7138..8f61351d 100644 --- a/aiogram/api/methods/answer_inline_query.py +++ b/aiogram/api/methods/answer_inline_query.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import InlineQueryResult from .base import Request, TelegramMethod, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class AnswerInlineQuery(TelegramMethod[bool]): """ @@ -36,8 +41,8 @@ class AnswerInlineQuery(TelegramMethod[bool]): """Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data["results"]) + prepare_parse_mode(bot, data["results"]) return Request(method="answerInlineQuery", data=data) diff --git a/aiogram/api/methods/answer_pre_checkout_query.py b/aiogram/api/methods/answer_pre_checkout_query.py index fae21d5c..1370c7b9 100644 --- a/aiogram/api/methods/answer_pre_checkout_query.py +++ b/aiogram/api/methods/answer_pre_checkout_query.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class AnswerPreCheckoutQuery(TelegramMethod[bool]): """ @@ -26,7 +31,7 @@ class AnswerPreCheckoutQuery(TelegramMethod[bool]): amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="answerPreCheckoutQuery", data=data) diff --git a/aiogram/api/methods/answer_shipping_query.py b/aiogram/api/methods/answer_shipping_query.py index 986d8fe6..708adb54 100644 --- a/aiogram/api/methods/answer_shipping_query.py +++ b/aiogram/api/methods/answer_shipping_query.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import ShippingOption from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class AnswerShippingQuery(TelegramMethod[bool]): """ @@ -27,7 +32,7 @@ class AnswerShippingQuery(TelegramMethod[bool]): impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="answerShippingQuery", data=data) diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py index 40f251c0..1ad41445 100644 --- a/aiogram/api/methods/base.py +++ b/aiogram/api/methods/base.py @@ -66,7 +66,7 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[T]): pass @abc.abstractmethod - def build_request(self) -> Request: # pragma: no cover + def build_request(self, bot: Bot) -> Request: # pragma: no cover pass def dict(self, **kwargs: Any) -> Any: @@ -125,7 +125,7 @@ def prepare_media_file(data: Dict[str, Any], files: Dict[str, InputFile]) -> Non data["media"]["media"] = f"attach://{tag}" -def prepare_parse_mode(root: Any, parse_mode_property: str = "parse_mode") -> None: +def prepare_parse_mode(bot: Bot, root: Any, parse_mode_property: str = "parse_mode") -> None: """ Find and set parse_mode with highest priority. @@ -136,14 +136,9 @@ def prepare_parse_mode(root: Any, parse_mode_property: str = "parse_mode") -> No """ if isinstance(root, list): for item in root: - prepare_parse_mode(item, parse_mode_property=parse_mode_property) - return - - if root.get(parse_mode_property, UNSET) is UNSET: - from ..client.bot import Bot - - bot = Bot.get_current(no_error=True) - if bot and bot.parse_mode: + prepare_parse_mode(bot=bot, root=item, parse_mode_property=parse_mode_property) + elif root.get(parse_mode_property, UNSET) is UNSET: + if bot.parse_mode: root[parse_mode_property] = bot.parse_mode else: root[parse_mode_property] = None diff --git a/aiogram/api/methods/create_new_sticker_set.py b/aiogram/api/methods/create_new_sticker_set.py index f495986c..86c843df 100644 --- a/aiogram/api/methods/create_new_sticker_set.py +++ b/aiogram/api/methods/create_new_sticker_set.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InputFile, MaskPosition from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class CreateNewStickerSet(TelegramMethod[bool]): """ @@ -40,7 +45,7 @@ class CreateNewStickerSet(TelegramMethod[bool]): mask_position: Optional[MaskPosition] = None """A JSON-serialized object for position where the mask should be placed on faces""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"png_sticker", "tgs_sticker"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/delete_chat_photo.py b/aiogram/api/methods/delete_chat_photo.py index dc9e075c..3d98b8c8 100644 --- a/aiogram/api/methods/delete_chat_photo.py +++ b/aiogram/api/methods/delete_chat_photo.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class DeleteChatPhoto(TelegramMethod[bool]): """ @@ -18,7 +23,7 @@ class DeleteChatPhoto(TelegramMethod[bool]): """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="deleteChatPhoto", data=data) diff --git a/aiogram/api/methods/delete_chat_sticker_set.py b/aiogram/api/methods/delete_chat_sticker_set.py index 45d473c0..0247503b 100644 --- a/aiogram/api/methods/delete_chat_sticker_set.py +++ b/aiogram/api/methods/delete_chat_sticker_set.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class DeleteChatStickerSet(TelegramMethod[bool]): """ @@ -19,7 +24,7 @@ class DeleteChatStickerSet(TelegramMethod[bool]): """Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="deleteChatStickerSet", data=data) diff --git a/aiogram/api/methods/delete_message.py b/aiogram/api/methods/delete_message.py index a38df0c0..a584c496 100644 --- a/aiogram/api/methods/delete_message.py +++ b/aiogram/api/methods/delete_message.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class DeleteMessage(TelegramMethod[bool]): """ @@ -28,7 +33,7 @@ class DeleteMessage(TelegramMethod[bool]): message_id: int """Identifier of the message to delete""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="deleteMessage", data=data) diff --git a/aiogram/api/methods/delete_sticker_from_set.py b/aiogram/api/methods/delete_sticker_from_set.py index 2637c599..6552c20a 100644 --- a/aiogram/api/methods/delete_sticker_from_set.py +++ b/aiogram/api/methods/delete_sticker_from_set.py @@ -1,7 +1,12 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class DeleteStickerFromSet(TelegramMethod[bool]): """ @@ -15,7 +20,7 @@ class DeleteStickerFromSet(TelegramMethod[bool]): sticker: str """File identifier of the sticker""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="deleteStickerFromSet", data=data) diff --git a/aiogram/api/methods/delete_webhook.py b/aiogram/api/methods/delete_webhook.py index 0783974e..a0033407 100644 --- a/aiogram/api/methods/delete_webhook.py +++ b/aiogram/api/methods/delete_webhook.py @@ -1,7 +1,12 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class DeleteWebhook(TelegramMethod[bool]): """ @@ -13,7 +18,7 @@ class DeleteWebhook(TelegramMethod[bool]): __returning__ = bool - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="deleteWebhook", data=data) diff --git a/aiogram/api/methods/edit_message_caption.py b/aiogram/api/methods/edit_message_caption.py index 733c357d..4c506344 100644 --- a/aiogram/api/methods/edit_message_caption.py +++ b/aiogram/api/methods/edit_message_caption.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import UNSET, InlineKeyboardMarkup, Message from .base import Request, TelegramMethod, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """ @@ -28,8 +33,8 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data) + prepare_parse_mode(bot, data) return Request(method="editMessageCaption", data=data) diff --git a/aiogram/api/methods/edit_message_live_location.py b/aiogram/api/methods/edit_message_live_location.py index ca54c11e..dde98984 100644 --- a/aiogram/api/methods/edit_message_live_location.py +++ b/aiogram/api/methods/edit_message_live_location.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """ @@ -30,7 +35,7 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="editMessageLiveLocation", data=data) diff --git a/aiogram/api/methods/edit_message_media.py b/aiogram/api/methods/edit_message_media.py index 88c43973..1e62a585 100644 --- a/aiogram/api/methods/edit_message_media.py +++ b/aiogram/api/methods/edit_message_media.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InlineKeyboardMarkup, InputFile, InputMedia, Message from .base import Request, TelegramMethod, prepare_media_file, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class EditMessageMedia(TelegramMethod[Union[Message, bool]]): """ @@ -30,9 +35,9 @@ class EditMessageMedia(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data["media"]) + prepare_parse_mode(bot, data["media"]) files: Dict[str, InputFile] = {} prepare_media_file(data=data, files=files) diff --git a/aiogram/api/methods/edit_message_reply_markup.py b/aiogram/api/methods/edit_message_reply_markup.py index 49dec7fc..e9a14c2c 100644 --- a/aiogram/api/methods/edit_message_reply_markup.py +++ b/aiogram/api/methods/edit_message_reply_markup.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): """ @@ -24,7 +29,7 @@ class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="editMessageReplyMarkup", data=data) diff --git a/aiogram/api/methods/edit_message_text.py b/aiogram/api/methods/edit_message_text.py index 23255e98..49af2cb2 100644 --- a/aiogram/api/methods/edit_message_text.py +++ b/aiogram/api/methods/edit_message_text.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import UNSET, InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class EditMessageText(TelegramMethod[Union[Message, bool]]): """ @@ -30,7 +35,7 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="editMessageText", data=data) diff --git a/aiogram/api/methods/export_chat_invite_link.py b/aiogram/api/methods/export_chat_invite_link.py index 923664e0..6398ab2f 100644 --- a/aiogram/api/methods/export_chat_invite_link.py +++ b/aiogram/api/methods/export_chat_invite_link.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class ExportChatInviteLink(TelegramMethod[str]): """ @@ -23,7 +28,7 @@ class ExportChatInviteLink(TelegramMethod[str]): """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="exportChatInviteLink", data=data) diff --git a/aiogram/api/methods/forward_message.py b/aiogram/api/methods/forward_message.py index d8082704..7ecab18a 100644 --- a/aiogram/api/methods/forward_message.py +++ b/aiogram/api/methods/forward_message.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class ForwardMessage(TelegramMethod[Message]): """ @@ -24,7 +29,7 @@ class ForwardMessage(TelegramMethod[Message]): disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="forwardMessage", data=data) diff --git a/aiogram/api/methods/get_chat.py b/aiogram/api/methods/get_chat.py index be1fe55d..6b6f33ae 100644 --- a/aiogram/api/methods/get_chat.py +++ b/aiogram/api/methods/get_chat.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from ..types import Chat from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetChat(TelegramMethod[Chat]): """ @@ -19,7 +24,7 @@ class GetChat(TelegramMethod[Chat]): """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getChat", data=data) diff --git a/aiogram/api/methods/get_chat_administrators.py b/aiogram/api/methods/get_chat_administrators.py index 75398f82..2792b08f 100644 --- a/aiogram/api/methods/get_chat_administrators.py +++ b/aiogram/api/methods/get_chat_administrators.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Union from ..types import ChatMember from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetChatAdministrators(TelegramMethod[List[ChatMember]]): """ @@ -20,7 +25,7 @@ class GetChatAdministrators(TelegramMethod[List[ChatMember]]): """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getChatAdministrators", data=data) diff --git a/aiogram/api/methods/get_chat_member.py b/aiogram/api/methods/get_chat_member.py index 69a1c6a3..731709d9 100644 --- a/aiogram/api/methods/get_chat_member.py +++ b/aiogram/api/methods/get_chat_member.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from ..types import ChatMember from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetChatMember(TelegramMethod[ChatMember]): """ @@ -20,7 +25,7 @@ class GetChatMember(TelegramMethod[ChatMember]): user_id: int """Unique identifier of the target user""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getChatMember", data=data) diff --git a/aiogram/api/methods/get_chat_members_count.py b/aiogram/api/methods/get_chat_members_count.py index 50b4f484..f1418ec9 100644 --- a/aiogram/api/methods/get_chat_members_count.py +++ b/aiogram/api/methods/get_chat_members_count.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetChatMembersCount(TelegramMethod[int]): """ @@ -16,7 +21,7 @@ class GetChatMembersCount(TelegramMethod[int]): """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getChatMembersCount", data=data) diff --git a/aiogram/api/methods/get_file.py b/aiogram/api/methods/get_file.py index f39f2ebf..fb144ad0 100644 --- a/aiogram/api/methods/get_file.py +++ b/aiogram/api/methods/get_file.py @@ -1,8 +1,13 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from ..types import File from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetFile(TelegramMethod[File]): """ @@ -22,7 +27,7 @@ class GetFile(TelegramMethod[File]): file_id: str """File identifier to get info about""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getFile", data=data) diff --git a/aiogram/api/methods/get_game_high_scores.py b/aiogram/api/methods/get_game_high_scores.py index 5f1b1bb3..3d672819 100644 --- a/aiogram/api/methods/get_game_high_scores.py +++ b/aiogram/api/methods/get_game_high_scores.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import GameHighScore from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetGameHighScores(TelegramMethod[List[GameHighScore]]): """ @@ -27,7 +32,7 @@ class GetGameHighScores(TelegramMethod[List[GameHighScore]]): inline_message_id: Optional[str] = None """Required if chat_id and message_id are not specified. Identifier of the inline message""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getGameHighScores", data=data) diff --git a/aiogram/api/methods/get_me.py b/aiogram/api/methods/get_me.py index f12f75fc..a14a4de7 100644 --- a/aiogram/api/methods/get_me.py +++ b/aiogram/api/methods/get_me.py @@ -1,8 +1,13 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from ..types import User from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetMe(TelegramMethod[User]): """ @@ -14,7 +19,7 @@ class GetMe(TelegramMethod[User]): __returning__ = User - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getMe", data=data) diff --git a/aiogram/api/methods/get_my_commands.py b/aiogram/api/methods/get_my_commands.py index 1e1d8f1f..b865b8ae 100644 --- a/aiogram/api/methods/get_my_commands.py +++ b/aiogram/api/methods/get_my_commands.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List from ..types import BotCommand from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetMyCommands(TelegramMethod[List[BotCommand]]): """ @@ -14,7 +19,7 @@ class GetMyCommands(TelegramMethod[List[BotCommand]]): __returning__ = List[BotCommand] - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getMyCommands", data=data) diff --git a/aiogram/api/methods/get_sticker_set.py b/aiogram/api/methods/get_sticker_set.py index f929117c..ca09587f 100644 --- a/aiogram/api/methods/get_sticker_set.py +++ b/aiogram/api/methods/get_sticker_set.py @@ -1,8 +1,13 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from ..types import StickerSet from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetStickerSet(TelegramMethod[StickerSet]): """ @@ -16,7 +21,7 @@ class GetStickerSet(TelegramMethod[StickerSet]): name: str """Name of the sticker set""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getStickerSet", data=data) diff --git a/aiogram/api/methods/get_updates.py b/aiogram/api/methods/get_updates.py index 20ca5a8a..5e03738f 100644 --- a/aiogram/api/methods/get_updates.py +++ b/aiogram/api/methods/get_updates.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import Update from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetUpdates(TelegramMethod[List[Update]]): """ @@ -37,7 +42,7 @@ class GetUpdates(TelegramMethod[List[Update]]): list to receive all updates regardless of type (default). If not specified, the previous setting will be used.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getUpdates", data=data) diff --git a/aiogram/api/methods/get_user_profile_photos.py b/aiogram/api/methods/get_user_profile_photos.py index def605c0..76fe0573 100644 --- a/aiogram/api/methods/get_user_profile_photos.py +++ b/aiogram/api/methods/get_user_profile_photos.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional from ..types import UserProfilePhotos from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): """ @@ -22,7 +27,7 @@ class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): """Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getUserProfilePhotos", data=data) diff --git a/aiogram/api/methods/get_webhook_info.py b/aiogram/api/methods/get_webhook_info.py index 8a147162..4fa3476a 100644 --- a/aiogram/api/methods/get_webhook_info.py +++ b/aiogram/api/methods/get_webhook_info.py @@ -1,8 +1,13 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from ..types import WebhookInfo from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class GetWebhookInfo(TelegramMethod[WebhookInfo]): """ @@ -15,7 +20,7 @@ class GetWebhookInfo(TelegramMethod[WebhookInfo]): __returning__ = WebhookInfo - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="getWebhookInfo", data=data) diff --git a/aiogram/api/methods/kick_chat_member.py b/aiogram/api/methods/kick_chat_member.py index 64af64a1..3c6e4a6e 100644 --- a/aiogram/api/methods/kick_chat_member.py +++ b/aiogram/api/methods/kick_chat_member.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import datetime -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class KickChatMember(TelegramMethod[bool]): """ @@ -25,7 +30,7 @@ class KickChatMember(TelegramMethod[bool]): """Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="kickChatMember", data=data) diff --git a/aiogram/api/methods/leave_chat.py b/aiogram/api/methods/leave_chat.py index 0827fc88..4505762f 100644 --- a/aiogram/api/methods/leave_chat.py +++ b/aiogram/api/methods/leave_chat.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class LeaveChat(TelegramMethod[bool]): """ @@ -16,7 +21,7 @@ class LeaveChat(TelegramMethod[bool]): """Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="leaveChat", data=data) diff --git a/aiogram/api/methods/pin_chat_message.py b/aiogram/api/methods/pin_chat_message.py index 3f8a442d..f8d30376 100644 --- a/aiogram/api/methods/pin_chat_message.py +++ b/aiogram/api/methods/pin_chat_message.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class PinChatMessage(TelegramMethod[bool]): """ @@ -23,7 +28,7 @@ class PinChatMessage(TelegramMethod[bool]): """Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="pinChatMessage", data=data) diff --git a/aiogram/api/methods/promote_chat_member.py b/aiogram/api/methods/promote_chat_member.py index db32fd5b..10b59765 100644 --- a/aiogram/api/methods/promote_chat_member.py +++ b/aiogram/api/methods/promote_chat_member.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class PromoteChatMember(TelegramMethod[bool]): """ @@ -39,7 +44,7 @@ class PromoteChatMember(TelegramMethod[bool]): privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="promoteChatMember", data=data) diff --git a/aiogram/api/methods/restrict_chat_member.py b/aiogram/api/methods/restrict_chat_member.py index 05dac3a3..21c06dd0 100644 --- a/aiogram/api/methods/restrict_chat_member.py +++ b/aiogram/api/methods/restrict_chat_member.py @@ -1,9 +1,14 @@ +from __future__ import annotations + import datetime -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ChatPermissions from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class RestrictChatMember(TelegramMethod[bool]): """ @@ -28,7 +33,7 @@ class RestrictChatMember(TelegramMethod[bool]): more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="restrictChatMember", data=data) diff --git a/aiogram/api/methods/send_animation.py b/aiogram/api/methods/send_animation.py index 955ed9e9..00ae7546 100644 --- a/aiogram/api/methods/send_animation.py +++ b/aiogram/api/methods/send_animation.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendAnimation(TelegramMethod[Message]): """ @@ -59,7 +64,7 @@ class SendAnimation(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"animation", "thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_audio.py b/aiogram/api/methods/send_audio.py index ca39408f..dcb58746 100644 --- a/aiogram/api/methods/send_audio.py +++ b/aiogram/api/methods/send_audio.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendAudio(TelegramMethod[Message]): """ @@ -59,7 +64,7 @@ class SendAudio(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"audio", "thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_chat_action.py b/aiogram/api/methods/send_chat_action.py index 7f5710a3..fd1be792 100644 --- a/aiogram/api/methods/send_chat_action.py +++ b/aiogram/api/methods/send_chat_action.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendChatAction(TelegramMethod[bool]): """ @@ -29,7 +34,7 @@ class SendChatAction(TelegramMethod[bool]): record_audio or upload_audio for audio files, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendChatAction", data=data) diff --git a/aiogram/api/methods/send_contact.py b/aiogram/api/methods/send_contact.py index b7569804..dee9f6b7 100644 --- a/aiogram/api/methods/send_contact.py +++ b/aiogram/api/methods/send_contact.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -9,6 +11,9 @@ from ..types import ( ) from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendContact(TelegramMethod[Message]): """ @@ -40,7 +45,7 @@ class SendContact(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendContact", data=data) diff --git a/aiogram/api/methods/send_dice.py b/aiogram/api/methods/send_dice.py index fb767799..c267c549 100644 --- a/aiogram/api/methods/send_dice.py +++ b/aiogram/api/methods/send_dice.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -9,6 +11,9 @@ from ..types import ( ) from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendDice(TelegramMethod[Message]): """ @@ -36,7 +41,7 @@ class SendDice(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendDice", data=data) diff --git a/aiogram/api/methods/send_document.py b/aiogram/api/methods/send_document.py index b6868135..07c91bf4 100644 --- a/aiogram/api/methods/send_document.py +++ b/aiogram/api/methods/send_document.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendDocument(TelegramMethod[Message]): """ @@ -52,7 +57,7 @@ class SendDocument(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"document", "thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_game.py b/aiogram/api/methods/send_game.py index 9d760555..f3113f6c 100644 --- a/aiogram/api/methods/send_game.py +++ b/aiogram/api/methods/send_game.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendGame(TelegramMethod[Message]): """ @@ -26,7 +31,7 @@ class SendGame(TelegramMethod[Message]): """A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendGame", data=data) diff --git a/aiogram/api/methods/send_invoice.py b/aiogram/api/methods/send_invoice.py index f66b6a80..e96c903d 100644 --- a/aiogram/api/methods/send_invoice.py +++ b/aiogram/api/methods/send_invoice.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import InlineKeyboardMarkup, LabeledPrice, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendInvoice(TelegramMethod[Message]): """ @@ -66,7 +71,7 @@ class SendInvoice(TelegramMethod[Message]): """A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendInvoice", data=data) diff --git a/aiogram/api/methods/send_location.py b/aiogram/api/methods/send_location.py index 541a81fc..8be75bd0 100644 --- a/aiogram/api/methods/send_location.py +++ b/aiogram/api/methods/send_location.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -9,6 +11,9 @@ from ..types import ( ) from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendLocation(TelegramMethod[Message]): """ @@ -39,7 +44,7 @@ class SendLocation(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendLocation", data=data) diff --git a/aiogram/api/methods/send_media_group.py b/aiogram/api/methods/send_media_group.py index 735711dc..9bb05c90 100644 --- a/aiogram/api/methods/send_media_group.py +++ b/aiogram/api/methods/send_media_group.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import InputFile, InputMediaPhoto, InputMediaVideo, Message from .base import Request, TelegramMethod, prepare_input_media, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class SendMediaGroup(TelegramMethod[List[Message]]): """ @@ -24,9 +29,9 @@ class SendMediaGroup(TelegramMethod[List[Message]]): reply_to_message_id: Optional[int] = None """If the messages are a reply, ID of the original message""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data["media"]) + prepare_parse_mode(bot, data["media"]) files: Dict[str, InputFile] = {} prepare_input_media(data, files) diff --git a/aiogram/api/methods/send_message.py b/aiogram/api/methods/send_message.py index 44cc0fd2..a00aa9bb 100644 --- a/aiogram/api/methods/send_message.py +++ b/aiogram/api/methods/send_message.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -10,6 +12,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class SendMessage(TelegramMethod[Message]): """ @@ -39,8 +44,8 @@ class SendMessage(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data) + prepare_parse_mode(bot, data) return Request(method="sendMessage", data=data) diff --git a/aiogram/api/methods/send_photo.py b/aiogram/api/methods/send_photo.py index ab37099d..968664d1 100644 --- a/aiogram/api/methods/send_photo.py +++ b/aiogram/api/methods/send_photo.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendPhoto(TelegramMethod[Message]): """ @@ -43,7 +48,7 @@ class SendPhoto(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"photo"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_poll.py b/aiogram/api/methods/send_poll.py index 95ed10ed..341c00d8 100644 --- a/aiogram/api/methods/send_poll.py +++ b/aiogram/api/methods/send_poll.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import datetime -from typing import Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from ..types import ( ForceReply, @@ -10,6 +12,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_parse_mode +if TYPE_CHECKING: + from ..client.bot import Bot + class SendPoll(TelegramMethod[Message]): """ @@ -59,8 +64,8 @@ class SendPoll(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() - prepare_parse_mode(data, parse_mode_property="explanation_parse_mode") + prepare_parse_mode(bot, data, parse_mode_property="explanation_parse_mode") return Request(method="sendPoll", data=data) diff --git a/aiogram/api/methods/send_sticker.py b/aiogram/api/methods/send_sticker.py index e110b2f8..835f1f4b 100644 --- a/aiogram/api/methods/send_sticker.py +++ b/aiogram/api/methods/send_sticker.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -10,6 +12,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendSticker(TelegramMethod[Message]): """ @@ -38,7 +43,7 @@ class SendSticker(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"sticker"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_venue.py b/aiogram/api/methods/send_venue.py index 0e03dc6a..62fa79ad 100644 --- a/aiogram/api/methods/send_venue.py +++ b/aiogram/api/methods/send_venue.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -9,6 +11,9 @@ from ..types import ( ) from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SendVenue(TelegramMethod[Message]): """ @@ -45,7 +50,7 @@ class SendVenue(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="sendVenue", data=data) diff --git a/aiogram/api/methods/send_video.py b/aiogram/api/methods/send_video.py index 8784d134..e56ae1c8 100644 --- a/aiogram/api/methods/send_video.py +++ b/aiogram/api/methods/send_video.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendVideo(TelegramMethod[Message]): """ @@ -60,7 +65,7 @@ class SendVideo(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"video", "thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_video_note.py b/aiogram/api/methods/send_video_note.py index bb41045a..2722706f 100644 --- a/aiogram/api/methods/send_video_note.py +++ b/aiogram/api/methods/send_video_note.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( ForceReply, @@ -10,6 +12,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendVideoNote(TelegramMethod[Message]): """ @@ -49,7 +54,7 @@ class SendVideoNote(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"video_note", "thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/send_voice.py b/aiogram/api/methods/send_voice.py index 945c6314..69b0dfbc 100644 --- a/aiogram/api/methods/send_voice.py +++ b/aiogram/api/methods/send_voice.py @@ -1,4 +1,6 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import ( UNSET, @@ -11,6 +13,9 @@ from ..types import ( ) from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SendVoice(TelegramMethod[Message]): """ @@ -49,7 +54,7 @@ class SendVoice(TelegramMethod[Message]): """Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"voice"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/set_chat_administrator_custom_title.py b/aiogram/api/methods/set_chat_administrator_custom_title.py index a153212a..01fe6757 100644 --- a/aiogram/api/methods/set_chat_administrator_custom_title.py +++ b/aiogram/api/methods/set_chat_administrator_custom_title.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatAdministratorCustomTitle(TelegramMethod[bool]): """ @@ -21,7 +26,7 @@ class SetChatAdministratorCustomTitle(TelegramMethod[bool]): custom_title: str """New custom title for the administrator; 0-16 characters, emoji are not allowed""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setChatAdministratorCustomTitle", data=data) diff --git a/aiogram/api/methods/set_chat_description.py b/aiogram/api/methods/set_chat_description.py index 38c35138..dba7fb7d 100644 --- a/aiogram/api/methods/set_chat_description.py +++ b/aiogram/api/methods/set_chat_description.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatDescription(TelegramMethod[bool]): """ @@ -20,7 +25,7 @@ class SetChatDescription(TelegramMethod[bool]): description: Optional[str] = None """New chat description, 0-255 characters""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setChatDescription", data=data) diff --git a/aiogram/api/methods/set_chat_permissions.py b/aiogram/api/methods/set_chat_permissions.py index 5e415340..aa314bb1 100644 --- a/aiogram/api/methods/set_chat_permissions.py +++ b/aiogram/api/methods/set_chat_permissions.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from ..types import ChatPermissions from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatPermissions(TelegramMethod[bool]): """ @@ -21,7 +26,7 @@ class SetChatPermissions(TelegramMethod[bool]): permissions: ChatPermissions """New default chat permissions""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setChatPermissions", data=data) diff --git a/aiogram/api/methods/set_chat_photo.py b/aiogram/api/methods/set_chat_photo.py index 4767edb0..4b1b4d0a 100644 --- a/aiogram/api/methods/set_chat_photo.py +++ b/aiogram/api/methods/set_chat_photo.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from ..types import InputFile from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatPhoto(TelegramMethod[bool]): """ @@ -21,7 +26,7 @@ class SetChatPhoto(TelegramMethod[bool]): photo: InputFile """New chat photo, uploaded using multipart/form-data""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"photo"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/set_chat_sticker_set.py b/aiogram/api/methods/set_chat_sticker_set.py index b7dc0ed0..7b4aefac 100644 --- a/aiogram/api/methods/set_chat_sticker_set.py +++ b/aiogram/api/methods/set_chat_sticker_set.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatStickerSet(TelegramMethod[bool]): """ @@ -21,7 +26,7 @@ class SetChatStickerSet(TelegramMethod[bool]): sticker_set_name: str """Name of the sticker set to be set as the group sticker set""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setChatStickerSet", data=data) diff --git a/aiogram/api/methods/set_chat_title.py b/aiogram/api/methods/set_chat_title.py index 8337a1a1..8dfcebc5 100644 --- a/aiogram/api/methods/set_chat_title.py +++ b/aiogram/api/methods/set_chat_title.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetChatTitle(TelegramMethod[bool]): """ @@ -20,7 +25,7 @@ class SetChatTitle(TelegramMethod[bool]): title: str """New chat title, 1-255 characters""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setChatTitle", data=data) diff --git a/aiogram/api/methods/set_game_score.py b/aiogram/api/methods/set_game_score.py index 5e5dc397..e9e27f69 100644 --- a/aiogram/api/methods/set_game_score.py +++ b/aiogram/api/methods/set_game_score.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetGameScore(TelegramMethod[Union[Message, bool]]): """ @@ -32,7 +37,7 @@ class SetGameScore(TelegramMethod[Union[Message, bool]]): inline_message_id: Optional[str] = None """Required if chat_id and message_id are not specified. Identifier of the inline message""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setGameScore", data=data) diff --git a/aiogram/api/methods/set_my_commands.py b/aiogram/api/methods/set_my_commands.py index 97ac9bcb..ee6e488e 100644 --- a/aiogram/api/methods/set_my_commands.py +++ b/aiogram/api/methods/set_my_commands.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List from ..types import BotCommand from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetMyCommands(TelegramMethod[bool]): """ @@ -17,7 +22,7 @@ class SetMyCommands(TelegramMethod[bool]): """A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setMyCommands", data=data) diff --git a/aiogram/api/methods/set_passport_data_errors.py b/aiogram/api/methods/set_passport_data_errors.py index 44753546..98e82068 100644 --- a/aiogram/api/methods/set_passport_data_errors.py +++ b/aiogram/api/methods/set_passport_data_errors.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List from ..types import PassportElementError from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetPassportDataErrors(TelegramMethod[bool]): """ @@ -24,7 +29,7 @@ class SetPassportDataErrors(TelegramMethod[bool]): errors: List[PassportElementError] """A JSON-serialized array describing the errors""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setPassportDataErrors", data=data) diff --git a/aiogram/api/methods/set_sticker_position_in_set.py b/aiogram/api/methods/set_sticker_position_in_set.py index 378a39d3..e4b81b23 100644 --- a/aiogram/api/methods/set_sticker_position_in_set.py +++ b/aiogram/api/methods/set_sticker_position_in_set.py @@ -1,7 +1,12 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class SetStickerPositionInSet(TelegramMethod[bool]): """ @@ -18,7 +23,7 @@ class SetStickerPositionInSet(TelegramMethod[bool]): position: int """New sticker position in the set, zero-based""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="setStickerPositionInSet", data=data) diff --git a/aiogram/api/methods/set_sticker_set_thumb.py b/aiogram/api/methods/set_sticker_set_thumb.py index 5ccd3bf3..15d1959e 100644 --- a/aiogram/api/methods/set_sticker_set_thumb.py +++ b/aiogram/api/methods/set_sticker_set_thumb.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InputFile from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SetStickerSetThumb(TelegramMethod[bool]): """ @@ -27,7 +32,7 @@ class SetStickerSetThumb(TelegramMethod[bool]): Internet, or upload a new one using multipart/form-data.. Animated sticker set thumbnail can't be uploaded via HTTP URL.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"thumb"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/set_webhook.py b/aiogram/api/methods/set_webhook.py index 7da2d287..c1533595 100644 --- a/aiogram/api/methods/set_webhook.py +++ b/aiogram/api/methods/set_webhook.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, List, Optional +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List, Optional from ..types import InputFile from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class SetWebhook(TelegramMethod[bool]): """ @@ -43,7 +48,7 @@ class SetWebhook(TelegramMethod[bool]): list to receive all updates regardless of type (default). If not specified, the previous setting will be used.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"certificate"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/api/methods/stop_message_live_location.py b/aiogram/api/methods/stop_message_live_location.py index f4f17910..552564ce 100644 --- a/aiogram/api/methods/stop_message_live_location.py +++ b/aiogram/api/methods/stop_message_live_location.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """ @@ -26,7 +31,7 @@ class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="stopMessageLiveLocation", data=data) diff --git a/aiogram/api/methods/stop_poll.py b/aiogram/api/methods/stop_poll.py index d6be55b9..fb7fca3b 100644 --- a/aiogram/api/methods/stop_poll.py +++ b/aiogram/api/methods/stop_poll.py @@ -1,8 +1,13 @@ -from typing import Any, Dict, Optional, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional, Union from ..types import InlineKeyboardMarkup, Poll from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class StopPoll(TelegramMethod[Poll]): """ @@ -22,7 +27,7 @@ class StopPoll(TelegramMethod[Poll]): reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new message inline keyboard.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="stopPoll", data=data) diff --git a/aiogram/api/methods/unban_chat_member.py b/aiogram/api/methods/unban_chat_member.py index 09e6da6f..0a4bb14b 100644 --- a/aiogram/api/methods/unban_chat_member.py +++ b/aiogram/api/methods/unban_chat_member.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class UnbanChatMember(TelegramMethod[bool]): """ @@ -20,7 +25,7 @@ class UnbanChatMember(TelegramMethod[bool]): user_id: int """Unique identifier of the target user""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="unbanChatMember", data=data) diff --git a/aiogram/api/methods/unpin_chat_message.py b/aiogram/api/methods/unpin_chat_message.py index c205884d..5a57ef25 100644 --- a/aiogram/api/methods/unpin_chat_message.py +++ b/aiogram/api/methods/unpin_chat_message.py @@ -1,7 +1,12 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union from .base import Request, TelegramMethod +if TYPE_CHECKING: + from ..client.bot import Bot + class UnpinChatMessage(TelegramMethod[bool]): """ @@ -18,7 +23,7 @@ class UnpinChatMessage(TelegramMethod[bool]): """Unique identifier for the target chat or username of the target channel (in the format @channelusername)""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() return Request(method="unpinChatMessage", data=data) diff --git a/aiogram/api/methods/upload_sticker_file.py b/aiogram/api/methods/upload_sticker_file.py index 7e806754..0e84e95a 100644 --- a/aiogram/api/methods/upload_sticker_file.py +++ b/aiogram/api/methods/upload_sticker_file.py @@ -1,8 +1,13 @@ -from typing import Any, Dict +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict from ..types import File, InputFile from .base import Request, TelegramMethod, prepare_file +if TYPE_CHECKING: + from ..client.bot import Bot + class UploadStickerFile(TelegramMethod[File]): """ @@ -20,7 +25,7 @@ class UploadStickerFile(TelegramMethod[File]): """PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.""" - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict(exclude={"png_sticker"}) files: Dict[str, InputFile] = {} diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 1c4b08aa..699f746d 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -219,7 +219,7 @@ class Dispatcher(Router): # TODO: handle exceptions response: Any = process_updates.result() if isinstance(response, TelegramMethod): - request = response.build_request() + request = response.build_request(bot=bot) return request.render_webhook_request() else: diff --git a/tests/mocked_bot.py b/tests/mocked_bot.py index 03242388..f0b1ead6 100644 --- a/tests/mocked_bot.py +++ b/tests/mocked_bot.py @@ -25,9 +25,9 @@ class MockedSession(BaseSession): pass async def make_request( - self, token: str, method: TelegramMethod[T], timeout: Optional[int] = UNSET + self, bot: Bot, method: TelegramMethod[T], timeout: Optional[int] = UNSET ) -> T: - self.requests.append(method.build_request()) + self.requests.append(method.build_request(bot)) response: Response[T] = self.responses.pop() self.raise_for_status(response) return response.result # type: ignore diff --git a/tests/test_api/test_client/test_bot.py b/tests/test_api/test_client/test_bot.py index 675c0dd3..b9dff9e7 100644 --- a/tests/test_api/test_client/test_bot.py +++ b/tests/test_api/test_client/test_bot.py @@ -42,12 +42,13 @@ class TestBot: new_callable=CoroutineMock, ) as mocked_make_request: await bot(method) - mocked_make_request.assert_awaited_with("42:TEST", method) + mocked_make_request.assert_awaited_with(bot, method, timeout=None) @pytest.mark.asyncio async def test_close(self): - bot = Bot("42:TEST", session=AiohttpSession()) - await bot.session.create_session() + session = AiohttpSession() + bot = Bot("42:TEST", session=session) + await session.create_session() with patch( "aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock diff --git a/tests/test_api/test_client/test_session/test_aiohttp_session.py b/tests/test_api/test_client/test_session/test_aiohttp_session.py index e7716f9a..bb89e888 100644 --- a/tests/test_api/test_client/test_session/test_aiohttp_session.py +++ b/tests/test_api/test_client/test_session/test_aiohttp_session.py @@ -5,9 +5,11 @@ import aiohttp_socks import pytest from aresponses import ResponsesMockServer +from aiogram import Bot from aiogram.api.client.session.aiohttp import AiohttpSession from aiogram.api.methods import Request, TelegramMethod from aiogram.api.types import InputFile +from tests.mocked_bot import MockedBot try: from asynctest import CoroutineMock, patch @@ -147,7 +149,7 @@ class TestAiohttpSession: assert isinstance(fields[1][2], BareInputFile) @pytest.mark.asyncio - async def test_make_request(self, aresponses: ResponsesMockServer): + async def test_make_request(self, bot: MockedBot, aresponses: ResponsesMockServer): aresponses.add( aresponses.ANY, "/bot42:TEST/method", @@ -164,14 +166,14 @@ class TestAiohttpSession: class TestMethod(TelegramMethod[int]): __returning__ = int - def build_request(self) -> Request: + def build_request(self, bot: Bot) -> Request: return Request(method="method", data={}) call = TestMethod() with patch( "aiogram.api.client.session.base.BaseSession.raise_for_status" ) as patched_raise_for_status: - result = await session.make_request("42:TEST", call) + result = await session.make_request(bot, call) assert isinstance(result, int) assert result == 42 diff --git a/tests/test_api/test_methods/test_answer_inline_query.py b/tests/test_api/test_methods/test_answer_inline_query.py index 84c0a05e..950502c9 100644 --- a/tests/test_api/test_methods/test_answer_inline_query.py +++ b/tests/test_api/test_methods/test_answer_inline_query.py @@ -29,17 +29,14 @@ class TestAnswerInlineQuery: assert request.method == "answerInlineQuery" assert response == prepare_result.result - def test_parse_mode(self): + def test_parse_mode(self, bot: MockedBot): query = AnswerInlineQuery( inline_query_id="query id", results=[InlineQueryResultPhoto(id="result id", photo_url="photo", thumb_url="thumb")], ) - request = query.build_request() + request = query.build_request(bot) assert request.data["results"][0]["parse_mode"] is None - token = Bot.set_current(Bot(token="42:TEST", parse_mode="HTML")) - try: - request = query.build_request() - assert request.data["results"][0]["parse_mode"] == "HTML" - finally: - Bot.reset_current(token) + new_bot = Bot(token="42:TEST", parse_mode="HTML") + request = query.build_request(new_bot) + assert request.data["results"][0]["parse_mode"] == "HTML" diff --git a/tests/test_api/test_methods/test_base.py b/tests/test_api/test_methods/test_base.py index e3627d54..3fd46078 100644 --- a/tests/test_api/test_methods/test_base.py +++ b/tests/test_api/test_methods/test_base.py @@ -4,6 +4,7 @@ import pytest from aiogram import Bot from aiogram.api.methods.base import prepare_parse_mode +from tests.mocked_bot import MockedBot class TestPrepareFile: @@ -35,19 +36,19 @@ class TestPrepareParseMode: ) @pytest.mark.asyncio async def test_default_parse_mode( - self, parse_mode: str, data: Dict[str, str], result: Optional[str] + self, bot: MockedBot, parse_mode: str, data: Dict[str, str], result: Optional[str] ): async with Bot(token="42:TEST", parse_mode=parse_mode).context() as bot: assert bot.parse_mode == parse_mode - prepare_parse_mode(data) + prepare_parse_mode(bot, data) assert data.get("parse_mode") == result @pytest.mark.asyncio async def test_list(self): data = [{}] * 2 data.append({"parse_mode": "HTML"}) - async with Bot(token="42:TEST", parse_mode="Markdown").context(): - prepare_parse_mode(data) + bot = Bot(token="42:TEST", parse_mode="Markdown") + prepare_parse_mode(bot, data) assert isinstance(data, list) assert len(data) == 3 @@ -56,7 +57,7 @@ class TestPrepareParseMode: assert data[1]["parse_mode"] == "Markdown" assert data[2]["parse_mode"] == "HTML" - def test_bot_not_in_context(self): + def test_bot_not_in_context(self, bot: MockedBot): data = {} - prepare_parse_mode(data) + prepare_parse_mode(bot, data) assert data["parse_mode"] is None