From aea876dfe0b3f7091fa51caa366b65de3d588709 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 2 Aug 2023 23:28:50 +0300 Subject: [PATCH] Added codegen configuration for lost shortcuts (#1244) * Added codegen configuration for lost shortcuts * Rollback inline_message_id * Added changelog --- .butcher/types/Message/aliases.yml | 18 ++++--- .butcher/types/PreCheckoutQuery/aliases.yml | 4 ++ .butcher/types/ShippingQuery/aliases.yml | 4 ++ CHANGES/#1244.bugfix.rst | 5 ++ aiogram/types/message.py | 52 ++++++++++++++++----- aiogram/types/pre_checkout_query.py | 32 ++++++++++--- aiogram/types/shipping_query.py | 28 ++++++++--- 7 files changed, 112 insertions(+), 31 deletions(-) create mode 100644 .butcher/types/PreCheckoutQuery/aliases.yml create mode 100644 .butcher/types/ShippingQuery/aliases.yml create mode 100644 CHANGES/#1244.bugfix.rst diff --git a/.butcher/types/Message/aliases.yml b/.butcher/types/Message/aliases.yml index 4d731875..290f9fa1 100644 --- a/.butcher/types/Message/aliases.yml +++ b/.butcher/types/Message/aliases.yml @@ -144,18 +144,18 @@ copy_to: from_chat_id: self.chat.id message_id: self.message_id -edit_text: - method: editMessageText - fill: &message-target - chat_id: self.chat.id - message_id: self.message_id - forward: method: forwardMessage fill: from_chat_id: self.chat.id message_id: self.message_id +edit_text: + method: editMessageText + fill: &message-target + chat_id: self.chat.id if self.chat else None + message_id: self.message_id + edit_media: method: editMessageMedia fill: *message-target @@ -164,6 +164,12 @@ edit_reply_markup: method: editMessageReplyMarkup fill: *message-target +delete_reply_markup: + method: editMessageReplyMarkup + fill: + <<: *message-target + reply_markup: None + edit_live_location: method: editMessageLiveLocation fill: *message-target diff --git a/.butcher/types/PreCheckoutQuery/aliases.yml b/.butcher/types/PreCheckoutQuery/aliases.yml new file mode 100644 index 00000000..780f3bd1 --- /dev/null +++ b/.butcher/types/PreCheckoutQuery/aliases.yml @@ -0,0 +1,4 @@ +answer: + method: answerPreCheckoutQuery + fill: + pre_checkout_query_id: self.id diff --git a/.butcher/types/ShippingQuery/aliases.yml b/.butcher/types/ShippingQuery/aliases.yml new file mode 100644 index 00000000..7fb73655 --- /dev/null +++ b/.butcher/types/ShippingQuery/aliases.yml @@ -0,0 +1,4 @@ +answer: + method: answerShippingQuery + fill: + shipping_query_id: self.id diff --git a/CHANGES/#1244.bugfix.rst b/CHANGES/#1244.bugfix.rst new file mode 100644 index 00000000..5d827461 --- /dev/null +++ b/CHANGES/#1244.bugfix.rst @@ -0,0 +1,5 @@ +Added codegen configuration for lost shortcuts: + +- ShippingQuery.answer +- PreCheckoutQuery.answer +- Message.delete_reply_markup diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 0e539042..3e14f8aa 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -2721,7 +2721,7 @@ class Message(TelegramObject): from aiogram.methods import EditMessageText return EditMessageText( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, text=text, inline_message_id=inline_message_id, @@ -2807,7 +2807,7 @@ class Message(TelegramObject): from aiogram.methods import EditMessageMedia return EditMessageMedia( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, media=media, inline_message_id=inline_message_id, @@ -2842,15 +2842,45 @@ class Message(TelegramObject): from aiogram.methods import EditMessageReplyMarkup return EditMessageReplyMarkup( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, inline_message_id=inline_message_id, reply_markup=reply_markup, **kwargs, ).as_(self._bot) - def delete_reply_markup(self) -> EditMessageReplyMarkup: - return self.edit_reply_markup(reply_markup=None) + def delete_reply_markup( + self, + inline_message_id: Optional[str] = None, + **kwargs: Any, + ) -> EditMessageReplyMarkup: + """ + Shortcut for method :class:`aiogram.methods.edit_message_reply_markup.EditMessageReplyMarkup` + will automatically fill method attributes: + + - :code:`chat_id` + - :code:`message_id` + - :code:`reply_markup` + + Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited :class:`aiogram.types.message.Message` is returned, otherwise :code:`True` is returned. + + Source: https://core.telegram.org/bots/api#editmessagereplymarkup + + :param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message + :return: instance of method :class:`aiogram.methods.edit_message_reply_markup.EditMessageReplyMarkup` + """ + # DO NOT EDIT MANUALLY!!! + # This method was auto-generated via `butcher` + + from aiogram.methods import EditMessageReplyMarkup + + return EditMessageReplyMarkup( + chat_id=self.chat.id if self.chat else None, + message_id=self.message_id, + reply_markup=None, + inline_message_id=inline_message_id, + **kwargs, + ).as_(self._bot) def edit_live_location( self, @@ -2889,7 +2919,7 @@ class Message(TelegramObject): from aiogram.methods import EditMessageLiveLocation return EditMessageLiveLocation( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, latitude=latitude, longitude=longitude, @@ -2928,7 +2958,7 @@ class Message(TelegramObject): from aiogram.methods import StopMessageLiveLocation return StopMessageLiveLocation( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, inline_message_id=inline_message_id, reply_markup=reply_markup, @@ -2968,7 +2998,7 @@ class Message(TelegramObject): from aiogram.methods import EditMessageCaption return EditMessageCaption( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, inline_message_id=inline_message_id, caption=caption, @@ -3019,7 +3049,7 @@ class Message(TelegramObject): from aiogram.methods import DeleteMessage return DeleteMessage( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, **kwargs, ).as_(self._bot) @@ -3049,7 +3079,7 @@ class Message(TelegramObject): from aiogram.methods import PinChatMessage return PinChatMessage( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, disable_notification=disable_notification, **kwargs, @@ -3078,7 +3108,7 @@ class Message(TelegramObject): from aiogram.methods import UnpinChatMessage return UnpinChatMessage( - chat_id=self.chat.id, + chat_id=self.chat.id if self.chat else None, message_id=self.message_id, **kwargs, ).as_(self._bot) diff --git a/aiogram/types/pre_checkout_query.py b/aiogram/types/pre_checkout_query.py index f2e49170..1084e76a 100644 --- a/aiogram/types/pre_checkout_query.py +++ b/aiogram/types/pre_checkout_query.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Any from pydantic import Field @@ -34,16 +34,34 @@ class PreCheckoutQuery(TelegramObject): order_info: Optional[OrderInfo] = None """*Optional*. Order information provided by the user""" - def answer(self, ok: bool, error_message: Optional[str] = None) -> AnswerPreCheckoutQuery: + def answer( + self, + ok: bool, + error_message: Optional[str] = None, + **kwargs: Any, + ) -> AnswerPreCheckoutQuery: """ - :param ok: - :param error_message: - :return: + Shortcut for method :class:`aiogram.methods.answer_pre_checkout_query.AnswerPreCheckoutQuery` + will automatically fill method attributes: + + - :code:`pre_checkout_query_id` + + Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an :class:`aiogram.types.update.Update` with the field *pre_checkout_query*. Use this method to respond to such pre-checkout queries. On success, :code:`True` is returned. **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + + Source: https://core.telegram.org/bots/api#answerprecheckoutquery + + :param ok: Specify :code:`True` if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use :code:`False` if there are any problems. + :param error_message: Required if *ok* is :code:`False`. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our 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. + :return: instance of method :class:`aiogram.methods.answer_pre_checkout_query.AnswerPreCheckoutQuery` """ - from ..methods import AnswerPreCheckoutQuery + # DO NOT EDIT MANUALLY!!! + # This method was auto-generated via `butcher` + + from aiogram.methods import AnswerPreCheckoutQuery return AnswerPreCheckoutQuery( pre_checkout_query_id=self.id, ok=ok, error_message=error_message, - ) + **kwargs, + ).as_(self._bot) diff --git a/aiogram/types/shipping_query.py b/aiogram/types/shipping_query.py index df00e38d..e1bbeca3 100644 --- a/aiogram/types/shipping_query.py +++ b/aiogram/types/shipping_query.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List, Optional, Any from pydantic import Field @@ -34,18 +34,32 @@ class ShippingQuery(TelegramObject): ok: bool, shipping_options: Optional[List[ShippingOption]] = None, error_message: Optional[str] = None, + **kwargs: Any, ) -> AnswerShippingQuery: """ - :param ok: - :param shipping_options: - :param error_message: - :return: + Shortcut for method :class:`aiogram.methods.answer_shipping_query.AnswerShippingQuery` + will automatically fill method attributes: + + - :code:`shipping_query_id` + + If you sent an invoice requesting a shipping address and the parameter *is_flexible* was specified, the Bot API will send an :class:`aiogram.types.update.Update` with a *shipping_query* field to the bot. Use this method to reply to shipping queries. On success, :code:`True` is returned. + + Source: https://core.telegram.org/bots/api#answershippingquery + + :param ok: Pass :code:`True` if delivery to the specified address is possible and :code:`False` if there are any problems (for example, if delivery to the specified address is not possible) + :param shipping_options: Required if *ok* is :code:`True`. A JSON-serialized array of available shipping options. + :param error_message: Required if *ok* is :code:`False`. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. + :return: instance of method :class:`aiogram.methods.answer_shipping_query.AnswerShippingQuery` """ - from ..methods import AnswerShippingQuery + # DO NOT EDIT MANUALLY!!! + # This method was auto-generated via `butcher` + + from aiogram.methods import AnswerShippingQuery return AnswerShippingQuery( shipping_query_id=self.id, ok=ok, shipping_options=shipping_options, error_message=error_message, - ) + **kwargs, + ).as_(self._bot)