diff --git a/aiogram/api/client/bot.py b/aiogram/api/client/bot.py index 723c615e..c1a2e2e1 100644 --- a/aiogram/api/client/bot.py +++ b/aiogram/api/client/bot.py @@ -95,9 +95,10 @@ from ..types import ( WebhookInfo, ) from .base import BaseBot +from ...utils.mixins import ContextInstanceMixin -class Bot(BaseBot): +class Bot(ContextInstanceMixin, BaseBot): """ Class where located all API methods """ diff --git a/aiogram/api/methods/add_sticker_to_set.py b/aiogram/api/methods/add_sticker_to_set.py index de458cb0..aaafb8c9 100644 --- a/aiogram/api/methods/add_sticker_to_set.py +++ b/aiogram/api/methods/add_sticker_to_set.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InputFile, MaskPosition from .base import Request, TelegramMethod +from ..types import InputFile, MaskPosition class AddStickerToSet(TelegramMethod[bool]): @@ -29,6 +29,9 @@ class AddStickerToSet(TelegramMethod[bool]): """A JSON-serialized object for position where the mask should be placed on faces""" def build_request(self) -> Request: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"png_sticker"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="png_sticker", value=self.png_sticker) + return Request(method="addStickerToSet", data=data, files=files) diff --git a/aiogram/api/methods/answer_callback_query.py b/aiogram/api/methods/answer_callback_query.py index 6e59ff85..7394a9ac 100644 --- a/aiogram/api/methods/answer_callback_query.py +++ b/aiogram/api/methods/answer_callback_query.py @@ -32,5 +32,5 @@ class AnswerCallbackQuery(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="answerCallbackQuery", data=data, files=files) + + 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 d0803347..a1302f15 100644 --- a/aiogram/api/methods/answer_inline_query.py +++ b/aiogram/api/methods/answer_inline_query.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import InlineQueryResult from .base import Request, TelegramMethod +from ..types import InlineQueryResult class AnswerInlineQuery(TelegramMethod[bool]): @@ -39,5 +39,5 @@ class AnswerInlineQuery(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="answerInlineQuery", data=data, files=files) + + 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 be25b0a3..e82325e3 100644 --- a/aiogram/api/methods/answer_pre_checkout_query.py +++ b/aiogram/api/methods/answer_pre_checkout_query.py @@ -23,5 +23,5 @@ class AnswerPreCheckoutQuery(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="answerPreCheckoutQuery", data=data, files=files) + + 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 dfafbc8d..3663bc15 100644 --- a/aiogram/api/methods/answer_shipping_query.py +++ b/aiogram/api/methods/answer_shipping_query.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import ShippingOption from .base import Request, TelegramMethod +from ..types import ShippingOption class AnswerShippingQuery(TelegramMethod[bool]): @@ -27,5 +27,5 @@ class AnswerShippingQuery(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="answerShippingQuery", data=data, files=files) + + return Request(method="answerShippingQuery", data=data) diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py index 35ef997b..3b0a230e 100644 --- a/aiogram/api/methods/base.py +++ b/aiogram/api/methods/base.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import abc import io -from typing import Any, Dict, Generic, Optional, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar, Union from pydantic import BaseConfig, BaseModel, Extra from pydantic.generics import GenericModel -from aiogram.api.types import InputFile, ResponseParameters +from ..types import InputFile, ResponseParameters + +if TYPE_CHECKING: + from ..client.bot import Bot T = TypeVar("T") @@ -47,3 +52,18 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[T]): def build_response(self, data: Dict[str, Any]) -> Response[T]: # noinspection PyTypeChecker return Response[self.__returning__](**data) # type: ignore + + def prepare_file(self, name: str, value: Any, data: Dict[str, Any], files: Dict[str, Any]): + if isinstance(value, InputFile): + files[name] = value + else: + data[name] = value + + async def emit(self, bot: Bot) -> T: + return await bot.emit(self) + + def __await__(self): + from aiogram.api.client.bot import Bot + + bot = Bot.get_current() + return self.emit(bot).__await__() diff --git a/aiogram/api/methods/create_new_sticker_set.py b/aiogram/api/methods/create_new_sticker_set.py index e53b7bfb..14ac7b6d 100644 --- a/aiogram/api/methods/create_new_sticker_set.py +++ b/aiogram/api/methods/create_new_sticker_set.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InputFile, MaskPosition from .base import Request, TelegramMethod +from ..types import InputFile, MaskPosition class CreateNewStickerSet(TelegramMethod[bool]): @@ -35,6 +35,9 @@ class CreateNewStickerSet(TelegramMethod[bool]): """A JSON-serialized object for position where the mask should be placed on faces""" def build_request(self) -> Request: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"png_sticker"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="png_sticker", value=self.png_sticker) + return Request(method="createNewStickerSet", data=data, files=files) diff --git a/aiogram/api/methods/delete_chat_photo.py b/aiogram/api/methods/delete_chat_photo.py index 60a20ddf..db844389 100644 --- a/aiogram/api/methods/delete_chat_photo.py +++ b/aiogram/api/methods/delete_chat_photo.py @@ -17,5 +17,5 @@ class DeleteChatPhoto(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="deleteChatPhoto", data=data, files=files) + + 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 0091171b..12f5ca38 100644 --- a/aiogram/api/methods/delete_chat_sticker_set.py +++ b/aiogram/api/methods/delete_chat_sticker_set.py @@ -17,5 +17,5 @@ class DeleteChatStickerSet(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="deleteChatStickerSet", data=data, files=files) + + return Request(method="deleteChatStickerSet", data=data) diff --git a/aiogram/api/methods/delete_message.py b/aiogram/api/methods/delete_message.py index a682b789..f1cd4309 100644 --- a/aiogram/api/methods/delete_message.py +++ b/aiogram/api/methods/delete_message.py @@ -27,5 +27,5 @@ class DeleteMessage(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="deleteMessage", data=data, files=files) + + 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 0f592edb..25bc0630 100644 --- a/aiogram/api/methods/delete_sticker_from_set.py +++ b/aiogram/api/methods/delete_sticker_from_set.py @@ -17,5 +17,5 @@ class DeleteStickerFromSet(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="deleteStickerFromSet", data=data, files=files) + + return Request(method="deleteStickerFromSet", data=data) diff --git a/aiogram/api/methods/delete_webhook.py b/aiogram/api/methods/delete_webhook.py index d9f1232e..a1c4e2ab 100644 --- a/aiogram/api/methods/delete_webhook.py +++ b/aiogram/api/methods/delete_webhook.py @@ -14,5 +14,5 @@ class DeleteWebhook(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="deleteWebhook", data=data, files=files) + + 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 4069b39c..7444fe64 100644 --- a/aiogram/api/methods/edit_message_caption.py +++ b/aiogram/api/methods/edit_message_caption.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class EditMessageCaption(TelegramMethod[Union[Message, bool]]): @@ -33,5 +33,5 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="editMessageCaption", data=data, files=files) + + 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 1cebf23b..27ead22f 100644 --- a/aiogram/api/methods/edit_message_live_location.py +++ b/aiogram/api/methods/edit_message_live_location.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): @@ -33,5 +33,5 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="editMessageLiveLocation", data=data, files=files) + + 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 251e7053..a1a156df 100644 --- a/aiogram/api/methods/edit_message_media.py +++ b/aiogram/api/methods/edit_message_media.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, InputMedia, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, InputMedia, Message class EditMessageMedia(TelegramMethod[Union[Message, bool]]): @@ -30,5 +30,5 @@ class EditMessageMedia(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="editMessageMedia", data=data, files=files) + + return Request(method="editMessageMedia", data=data) diff --git a/aiogram/api/methods/edit_message_reply_markup.py b/aiogram/api/methods/edit_message_reply_markup.py index 8651bc52..ada30b43 100644 --- a/aiogram/api/methods/edit_message_reply_markup.py +++ b/aiogram/api/methods/edit_message_reply_markup.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): @@ -27,5 +27,5 @@ class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="editMessageReplyMarkup", data=data, files=files) + + 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 96886e80..d510415e 100644 --- a/aiogram/api/methods/edit_message_text.py +++ b/aiogram/api/methods/edit_message_text.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class EditMessageText(TelegramMethod[Union[Message, bool]]): @@ -36,5 +36,5 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="editMessageText", data=data, files=files) + + 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 a7035c80..54e8f53b 100644 --- a/aiogram/api/methods/export_chat_invite_link.py +++ b/aiogram/api/methods/export_chat_invite_link.py @@ -18,5 +18,5 @@ class ExportChatInviteLink(TelegramMethod[str]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="exportChatInviteLink", data=data, files=files) + + return Request(method="exportChatInviteLink", data=data) diff --git a/aiogram/api/methods/forward_message.py b/aiogram/api/methods/forward_message.py index cc9f95fa..e3c8b741 100644 --- a/aiogram/api/methods/forward_message.py +++ b/aiogram/api/methods/forward_message.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import Message from .base import Request, TelegramMethod +from ..types import Message class ForwardMessage(TelegramMethod[Message]): @@ -27,5 +27,5 @@ class ForwardMessage(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="forwardMessage", data=data, files=files) + + return Request(method="forwardMessage", data=data) diff --git a/aiogram/api/methods/get_chat.py b/aiogram/api/methods/get_chat.py index a4833fcb..0dba87bd 100644 --- a/aiogram/api/methods/get_chat.py +++ b/aiogram/api/methods/get_chat.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Union -from ..types import Chat from .base import Request, TelegramMethod +from ..types import Chat class GetChat(TelegramMethod[Chat]): @@ -18,5 +18,5 @@ class GetChat(TelegramMethod[Chat]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getChat", data=data, files=files) + + 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 ba01f7b2..a5b407f1 100644 --- a/aiogram/api/methods/get_chat_administrators.py +++ b/aiogram/api/methods/get_chat_administrators.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Union -from ..types import ChatMember from .base import Request, TelegramMethod +from ..types import ChatMember class GetChatAdministrators(TelegramMethod[List[ChatMember]]): @@ -18,5 +18,5 @@ class GetChatAdministrators(TelegramMethod[List[ChatMember]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getChatAdministrators", data=data, files=files) + + 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 4a6e2e34..5e9a828a 100644 --- a/aiogram/api/methods/get_chat_member.py +++ b/aiogram/api/methods/get_chat_member.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Union -from ..types import ChatMember from .base import Request, TelegramMethod +from ..types import ChatMember class GetChatMember(TelegramMethod[ChatMember]): @@ -21,5 +21,5 @@ class GetChatMember(TelegramMethod[ChatMember]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getChatMember", data=data, files=files) + + 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 699b60e9..dd76abfa 100644 --- a/aiogram/api/methods/get_chat_members_count.py +++ b/aiogram/api/methods/get_chat_members_count.py @@ -17,5 +17,5 @@ class GetChatMembersCount(TelegramMethod[int]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getChatMembersCount", data=data, files=files) + + return Request(method="getChatMembersCount", data=data) diff --git a/aiogram/api/methods/get_file.py b/aiogram/api/methods/get_file.py index 7f18bc34..691c253c 100644 --- a/aiogram/api/methods/get_file.py +++ b/aiogram/api/methods/get_file.py @@ -1,7 +1,7 @@ from typing import Any, Dict -from ..types import File from .base import Request, TelegramMethod +from ..types import File class GetFile(TelegramMethod[File]): @@ -19,5 +19,5 @@ class GetFile(TelegramMethod[File]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getFile", data=data, files=files) + + 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 b7b294aa..988ace1a 100644 --- a/aiogram/api/methods/get_game_high_scores.py +++ b/aiogram/api/methods/get_game_high_scores.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import GameHighScore from .base import Request, TelegramMethod +from ..types import GameHighScore class GetGameHighScores(TelegramMethod[List[GameHighScore]]): @@ -28,5 +28,5 @@ class GetGameHighScores(TelegramMethod[List[GameHighScore]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getGameHighScores", data=data, files=files) + + return Request(method="getGameHighScores", data=data) diff --git a/aiogram/api/methods/get_me.py b/aiogram/api/methods/get_me.py index d4fc2980..f84b59f7 100644 --- a/aiogram/api/methods/get_me.py +++ b/aiogram/api/methods/get_me.py @@ -1,7 +1,7 @@ from typing import Any, Dict -from ..types import User from .base import Request, TelegramMethod +from ..types import User class GetMe(TelegramMethod[User]): @@ -15,5 +15,5 @@ class GetMe(TelegramMethod[User]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getMe", data=data, files=files) + + return Request(method="getMe", data=data) diff --git a/aiogram/api/methods/get_sticker_set.py b/aiogram/api/methods/get_sticker_set.py index 8fd9bcdb..11b28e98 100644 --- a/aiogram/api/methods/get_sticker_set.py +++ b/aiogram/api/methods/get_sticker_set.py @@ -1,7 +1,7 @@ from typing import Any, Dict -from ..types import StickerSet from .base import Request, TelegramMethod +from ..types import StickerSet class GetStickerSet(TelegramMethod[StickerSet]): @@ -18,5 +18,5 @@ class GetStickerSet(TelegramMethod[StickerSet]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getStickerSet", data=data, files=files) + + return Request(method="getStickerSet", data=data) diff --git a/aiogram/api/methods/get_updates.py b/aiogram/api/methods/get_updates.py index 15567f64..cb906bff 100644 --- a/aiogram/api/methods/get_updates.py +++ b/aiogram/api/methods/get_updates.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import Update from .base import Request, TelegramMethod +from ..types import Update class GetUpdates(TelegramMethod[List[Update]]): @@ -32,5 +32,5 @@ class GetUpdates(TelegramMethod[List[Update]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getUpdates", data=data, files=files) + + 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 b42c0c73..4ae06909 100644 --- a/aiogram/api/methods/get_user_profile_photos.py +++ b/aiogram/api/methods/get_user_profile_photos.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional -from ..types import UserProfilePhotos from .base import Request, TelegramMethod +from ..types import UserProfilePhotos class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): @@ -24,5 +24,5 @@ class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getUserProfilePhotos", data=data, files=files) + + 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 a034039e..f7fe8dda 100644 --- a/aiogram/api/methods/get_webhook_info.py +++ b/aiogram/api/methods/get_webhook_info.py @@ -1,7 +1,7 @@ from typing import Any, Dict -from ..types import WebhookInfo from .base import Request, TelegramMethod +from ..types import WebhookInfo class GetWebhookInfo(TelegramMethod[WebhookInfo]): @@ -15,5 +15,5 @@ class GetWebhookInfo(TelegramMethod[WebhookInfo]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="getWebhookInfo", data=data, files=files) + + 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 1542ce79..408af800 100644 --- a/aiogram/api/methods/kick_chat_member.py +++ b/aiogram/api/methods/kick_chat_member.py @@ -23,5 +23,5 @@ class KickChatMember(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="kickChatMember", data=data, files=files) + + return Request(method="kickChatMember", data=data) diff --git a/aiogram/api/methods/leave_chat.py b/aiogram/api/methods/leave_chat.py index fafaf7a6..fc2ee7d2 100644 --- a/aiogram/api/methods/leave_chat.py +++ b/aiogram/api/methods/leave_chat.py @@ -17,5 +17,5 @@ class LeaveChat(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="leaveChat", data=data, files=files) + + 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 6e4f5974..1308a8d7 100644 --- a/aiogram/api/methods/pin_chat_message.py +++ b/aiogram/api/methods/pin_chat_message.py @@ -23,5 +23,5 @@ class PinChatMessage(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="pinChatMessage", data=data, files=files) + + 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 34a30da9..b45d8981 100644 --- a/aiogram/api/methods/promote_chat_member.py +++ b/aiogram/api/methods/promote_chat_member.py @@ -44,5 +44,5 @@ class PromoteChatMember(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="promoteChatMember", data=data, files=files) + + 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 16ebe23e..36015a09 100644 --- a/aiogram/api/methods/restrict_chat_member.py +++ b/aiogram/api/methods/restrict_chat_member.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import ChatPermissions from .base import Request, TelegramMethod +from ..types import ChatPermissions class RestrictChatMember(TelegramMethod[bool]): @@ -27,5 +27,5 @@ class RestrictChatMember(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="restrictChatMember", data=data, files=files) + + return Request(method="restrictChatMember", data=data) diff --git a/aiogram/api/methods/send_animation.py b/aiogram/api/methods/send_animation.py index 36e1fe56..18d96aff 100644 --- a/aiogram/api/methods/send_animation.py +++ b/aiogram/api/methods/send_animation.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendAnimation(TelegramMethod[Message]): @@ -56,6 +56,10 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"animation", "thumb"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="animation", value=self.animation) + self.prepare_file(data=data, files=files, name="thumb", value=self.thumb) + return Request(method="sendAnimation", data=data, files=files) diff --git a/aiogram/api/methods/send_audio.py b/aiogram/api/methods/send_audio.py index e6ae098d..83eb0b89 100644 --- a/aiogram/api/methods/send_audio.py +++ b/aiogram/api/methods/send_audio.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendAudio(TelegramMethod[Message]): @@ -57,6 +57,10 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"audio", "thumb"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="audio", value=self.audio) + self.prepare_file(data=data, files=files, name="thumb", value=self.thumb) + return Request(method="sendAudio", data=data, files=files) diff --git a/aiogram/api/methods/send_chat_action.py b/aiogram/api/methods/send_chat_action.py index 0bbc81f1..80bda272 100644 --- a/aiogram/api/methods/send_chat_action.py +++ b/aiogram/api/methods/send_chat_action.py @@ -22,5 +22,5 @@ class SendChatAction(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendChatAction", data=data, files=files) + + return Request(method="sendChatAction", data=data) diff --git a/aiogram/api/methods/send_contact.py b/aiogram/api/methods/send_contact.py index 4e620e8a..a2f9a986 100644 --- a/aiogram/api/methods/send_contact.py +++ b/aiogram/api/methods/send_contact.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -7,7 +8,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendContact(TelegramMethod[Message]): @@ -47,5 +47,5 @@ class SendContact(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendContact", data=data, files=files) + + return Request(method="sendContact", data=data) diff --git a/aiogram/api/methods/send_document.py b/aiogram/api/methods/send_document.py index 93e0a2bc..23a635d9 100644 --- a/aiogram/api/methods/send_document.py +++ b/aiogram/api/methods/send_document.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendDocument(TelegramMethod[Message]): @@ -47,6 +47,10 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"document", "thumb"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="document", value=self.document) + self.prepare_file(data=data, files=files, name="thumb", value=self.thumb) + return Request(method="sendDocument", data=data, files=files) diff --git a/aiogram/api/methods/send_game.py b/aiogram/api/methods/send_game.py index 33461b8d..1b2a24f2 100644 --- a/aiogram/api/methods/send_game.py +++ b/aiogram/api/methods/send_game.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class SendGame(TelegramMethod[Message]): @@ -30,5 +30,5 @@ class SendGame(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendGame", data=data, files=files) + + return Request(method="sendGame", data=data) diff --git a/aiogram/api/methods/send_invoice.py b/aiogram/api/methods/send_invoice.py index 38b72a5a..c811ced3 100644 --- a/aiogram/api/methods/send_invoice.py +++ b/aiogram/api/methods/send_invoice.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import InlineKeyboardMarkup, LabeledPrice, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, LabeledPrice, Message class SendInvoice(TelegramMethod[Message]): @@ -84,5 +84,5 @@ class SendInvoice(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendInvoice", data=data, files=files) + + return Request(method="sendInvoice", data=data) diff --git a/aiogram/api/methods/send_location.py b/aiogram/api/methods/send_location.py index e46a89a9..eba40e0f 100644 --- a/aiogram/api/methods/send_location.py +++ b/aiogram/api/methods/send_location.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -7,7 +8,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendLocation(TelegramMethod[Message]): @@ -44,5 +44,5 @@ class SendLocation(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendLocation", data=data, files=files) + + 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 18c158dc..d6661aac 100644 --- a/aiogram/api/methods/send_media_group.py +++ b/aiogram/api/methods/send_media_group.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional, Union -from ..types import InputMediaPhoto, InputMediaVideo, Message from .base import Request, TelegramMethod +from ..types import InputMediaPhoto, InputMediaVideo, Message class SendMediaGroup(TelegramMethod[List[Message]]): @@ -27,5 +27,5 @@ class SendMediaGroup(TelegramMethod[List[Message]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendMediaGroup", data=data, files=files) + + return Request(method="sendMediaGroup", data=data) diff --git a/aiogram/api/methods/send_message.py b/aiogram/api/methods/send_message.py index c5927651..143ff7d6 100644 --- a/aiogram/api/methods/send_message.py +++ b/aiogram/api/methods/send_message.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -7,7 +8,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendMessage(TelegramMethod[Message]): @@ -44,5 +44,5 @@ class SendMessage(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendMessage", data=data, files=files) + + return Request(method="sendMessage", data=data) diff --git a/aiogram/api/methods/send_photo.py b/aiogram/api/methods/send_photo.py index d37c7dec..3d268b7e 100644 --- a/aiogram/api/methods/send_photo.py +++ b/aiogram/api/methods/send_photo.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendPhoto(TelegramMethod[Message]): @@ -44,6 +44,9 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"photo"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="photo", value=self.photo) + return Request(method="sendPhoto", data=data, files=files) diff --git a/aiogram/api/methods/send_poll.py b/aiogram/api/methods/send_poll.py index 2da01454..26c6a657 100644 --- a/aiogram/api/methods/send_poll.py +++ b/aiogram/api/methods/send_poll.py @@ -1,5 +1,6 @@ from typing import Any, Dict, List, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -7,7 +8,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendPoll(TelegramMethod[Message]): @@ -41,5 +41,5 @@ class SendPoll(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendPoll", data=data, files=files) + + return Request(method="sendPoll", data=data) diff --git a/aiogram/api/methods/send_sticker.py b/aiogram/api/methods/send_sticker.py index c9adb11f..630f4575 100644 --- a/aiogram/api/methods/send_sticker.py +++ b/aiogram/api/methods/send_sticker.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendSticker(TelegramMethod[Message]): @@ -38,6 +38,9 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"sticker"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="sticker", value=self.sticker) + return Request(method="sendSticker", data=data, files=files) diff --git a/aiogram/api/methods/send_venue.py b/aiogram/api/methods/send_venue.py index 229c103a..292a41db 100644 --- a/aiogram/api/methods/send_venue.py +++ b/aiogram/api/methods/send_venue.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -7,7 +8,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendVenue(TelegramMethod[Message]): @@ -53,5 +53,5 @@ class SendVenue(TelegramMethod[Message]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="sendVenue", data=data, files=files) + + return Request(method="sendVenue", data=data) diff --git a/aiogram/api/methods/send_video.py b/aiogram/api/methods/send_video.py index 34af89ab..c875fcbd 100644 --- a/aiogram/api/methods/send_video.py +++ b/aiogram/api/methods/send_video.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendVideo(TelegramMethod[Message]): @@ -59,6 +59,10 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"video", "thumb"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="video", value=self.video) + self.prepare_file(data=data, files=files, name="thumb", value=self.thumb) + return Request(method="sendVideo", data=data, files=files) diff --git a/aiogram/api/methods/send_video_note.py b/aiogram/api/methods/send_video_note.py index b856e082..85649115 100644 --- a/aiogram/api/methods/send_video_note.py +++ b/aiogram/api/methods/send_video_note.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendVideoNote(TelegramMethod[Message]): @@ -47,6 +47,10 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"video_note", "thumb"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="video_note", value=self.video_note) + self.prepare_file(data=data, files=files, name="thumb", value=self.thumb) + return Request(method="sendVideoNote", data=data, files=files) diff --git a/aiogram/api/methods/send_voice.py b/aiogram/api/methods/send_voice.py index 7988310f..eb51f5dd 100644 --- a/aiogram/api/methods/send_voice.py +++ b/aiogram/api/methods/send_voice.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Union +from .base import Request, TelegramMethod from ..types import ( ForceReply, InlineKeyboardMarkup, @@ -8,7 +9,6 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod class SendVoice(TelegramMethod[Message]): @@ -47,6 +47,9 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"voice"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="voice", value=self.voice) + return Request(method="sendVoice", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_description.py b/aiogram/api/methods/set_chat_description.py index ebbb62c0..08b6cc2d 100644 --- a/aiogram/api/methods/set_chat_description.py +++ b/aiogram/api/methods/set_chat_description.py @@ -20,5 +20,5 @@ class SetChatDescription(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setChatDescription", data=data, files=files) + + 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 906c9739..2aa7f225 100644 --- a/aiogram/api/methods/set_chat_permissions.py +++ b/aiogram/api/methods/set_chat_permissions.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Union -from ..types import ChatPermissions from .base import Request, TelegramMethod +from ..types import ChatPermissions class SetChatPermissions(TelegramMethod[bool]): @@ -21,5 +21,5 @@ class SetChatPermissions(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setChatPermissions", data=data, files=files) + + 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 6b835f6a..4f047531 100644 --- a/aiogram/api/methods/set_chat_photo.py +++ b/aiogram/api/methods/set_chat_photo.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Union -from ..types import InputFile from .base import Request, TelegramMethod +from ..types import InputFile class SetChatPhoto(TelegramMethod[bool]): @@ -20,6 +20,9 @@ class SetChatPhoto(TelegramMethod[bool]): """New chat photo, uploaded using multipart/form-data""" def build_request(self) -> Request: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"photo"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="photo", value=self.photo) + return Request(method="setChatPhoto", data=data, files=files) diff --git a/aiogram/api/methods/set_chat_sticker_set.py b/aiogram/api/methods/set_chat_sticker_set.py index 002dcafc..914a8213 100644 --- a/aiogram/api/methods/set_chat_sticker_set.py +++ b/aiogram/api/methods/set_chat_sticker_set.py @@ -20,5 +20,5 @@ class SetChatStickerSet(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setChatStickerSet", data=data, files=files) + + 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 037c268e..37ba9127 100644 --- a/aiogram/api/methods/set_chat_title.py +++ b/aiogram/api/methods/set_chat_title.py @@ -20,5 +20,5 @@ class SetChatTitle(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setChatTitle", data=data, files=files) + + 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 fa8675f1..3e8d1785 100644 --- a/aiogram/api/methods/set_game_score.py +++ b/aiogram/api/methods/set_game_score.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import Message from .base import Request, TelegramMethod +from ..types import Message class SetGameScore(TelegramMethod[Union[Message, bool]]): @@ -36,5 +36,5 @@ class SetGameScore(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setGameScore", data=data, files=files) + + return Request(method="setGameScore", data=data) diff --git a/aiogram/api/methods/set_passport_data_errors.py b/aiogram/api/methods/set_passport_data_errors.py index 65c4ac43..8e4eac3f 100644 --- a/aiogram/api/methods/set_passport_data_errors.py +++ b/aiogram/api/methods/set_passport_data_errors.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List -from ..types import PassportElementError from .base import Request, TelegramMethod +from ..types import PassportElementError class SetPassportDataErrors(TelegramMethod[bool]): @@ -22,5 +22,5 @@ class SetPassportDataErrors(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setPassportDataErrors", data=data, files=files) + + 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 844c9fd8..94ec063a 100644 --- a/aiogram/api/methods/set_sticker_position_in_set.py +++ b/aiogram/api/methods/set_sticker_position_in_set.py @@ -20,5 +20,5 @@ class SetStickerPositionInSet(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="setStickerPositionInSet", data=data, files=files) + + return Request(method="setStickerPositionInSet", data=data) diff --git a/aiogram/api/methods/set_webhook.py b/aiogram/api/methods/set_webhook.py index 05b2cfed..579d7cbd 100644 --- a/aiogram/api/methods/set_webhook.py +++ b/aiogram/api/methods/set_webhook.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from ..types import InputFile from .base import Request, TelegramMethod +from ..types import InputFile class SetWebhook(TelegramMethod[bool]): @@ -34,6 +34,9 @@ class SetWebhook(TelegramMethod[bool]): Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.""" def build_request(self) -> Request: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"certificate"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="certificate", value=self.certificate) + return Request(method="setWebhook", data=data, files=files) diff --git a/aiogram/api/methods/stop_message_live_location.py b/aiogram/api/methods/stop_message_live_location.py index 5d3591da..3c269ab7 100644 --- a/aiogram/api/methods/stop_message_live_location.py +++ b/aiogram/api/methods/stop_message_live_location.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Message class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): @@ -27,5 +27,5 @@ class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="stopMessageLiveLocation", data=data, files=files) + + return Request(method="stopMessageLiveLocation", data=data) diff --git a/aiogram/api/methods/stop_poll.py b/aiogram/api/methods/stop_poll.py index 8a93235d..98576b3a 100644 --- a/aiogram/api/methods/stop_poll.py +++ b/aiogram/api/methods/stop_poll.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Poll from .base import Request, TelegramMethod +from ..types import InlineKeyboardMarkup, Poll class StopPoll(TelegramMethod[Poll]): @@ -24,5 +24,5 @@ class StopPoll(TelegramMethod[Poll]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="stopPoll", data=data, files=files) + + 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 315f9a8e..0c7c4251 100644 --- a/aiogram/api/methods/unban_chat_member.py +++ b/aiogram/api/methods/unban_chat_member.py @@ -20,5 +20,5 @@ class UnbanChatMember(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="unbanChatMember", data=data, files=files) + + 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 b9a5f14d..382321af 100644 --- a/aiogram/api/methods/unpin_chat_message.py +++ b/aiogram/api/methods/unpin_chat_message.py @@ -17,5 +17,5 @@ class UnpinChatMessage(TelegramMethod[bool]): def build_request(self) -> Request: data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) - files: Dict[str, Any] = {} - return Request(method="unpinChatMessage", data=data, files=files) + + 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 f095dcdc..e15317c2 100644 --- a/aiogram/api/methods/upload_sticker_file.py +++ b/aiogram/api/methods/upload_sticker_file.py @@ -1,7 +1,7 @@ from typing import Any, Dict -from ..types import File, InputFile from .base import Request, TelegramMethod +from ..types import File, InputFile class UploadStickerFile(TelegramMethod[File]): @@ -20,6 +20,9 @@ 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: - data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={}) + data: Dict[str, Any] = self.dict(exclude_unset=True, exclude={"png_sticker"}) + files: Dict[str, Any] = {} + self.prepare_file(data=data, files=files, name="png_sticker", value=self.png_sticker) + return Request(method="uploadStickerFile", data=data, files=files)