remove methods that may not be accessible for the InaccessibleMessage type, add tests

This commit is contained in:
latan 2024-09-06 12:11:44 +03:00
parent ffb16aa628
commit 8dd67d5dd1
3 changed files with 152 additions and 700 deletions

View file

@ -200,76 +200,3 @@ reply_paid_media:
code: *assert-chat code: *assert-chat
fill: *fill-reply fill: *fill-reply
ignore: *ignore-reply ignore: *ignore-reply
copy_to:
method: copyMessage
code: *assert-chat
fill:
from_chat_id: self.chat.id
message_id: self.message_id
forward:
method: forwardMessage
code: *assert-chat
fill:
from_chat_id: self.chat.id
message_id: self.message_id
edit_text:
method: editMessageText
code: *assert-chat
fill: &message-target
chat_id: self.chat.id
message_id: self.message_id
edit_media:
method: editMessageMedia
fill: *message-target
code: *assert-chat
edit_reply_markup:
method: editMessageReplyMarkup
code: *assert-chat
fill: *message-target
delete_reply_markup:
method: editMessageReplyMarkup
code: *assert-chat
fill:
<<: *message-target
reply_markup: None
edit_live_location:
method: editMessageLiveLocation
code: *assert-chat
fill: *message-target
stop_live_location:
method: stopMessageLiveLocation
code: *assert-chat
fill: *message-target
edit_caption:
method: editMessageCaption
code: *assert-chat
fill: *message-target
delete:
method: deleteMessage
code: *assert-chat
fill: *message-target
pin:
method: pinChatMessage
code: *assert-chat
fill: *message-target
unpin:
method: unpinChatMessage
code: *assert-chat
fill: *message-target
react:
method: setMessageReaction
code: *assert-chat
fill: *message-target

View file

@ -1039,7 +1039,7 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
:param title: Product name, 1-32 characters :param title: Product name, 1-32 characters
:param description: Product description, 1-255 characters :param description: Product description, 1-255 characters
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. :param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
:param currency: Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass 'XTR' for payments in `Telegram Stars <https://t.me/BotNews/90>`_. :param currency: Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass 'XTR' for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
:param prices: Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_. :param prices: Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
@ -1155,7 +1155,7 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
:param title: Product name, 1-32 characters :param title: Product name, 1-32 characters
:param description: Product description, 1-255 characters :param description: Product description, 1-255 characters
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. :param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
:param currency: Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass 'XTR' for payments in `Telegram Stars <https://t.me/BotNews/90>`_. :param currency: Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass 'XTR' for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
:param prices: Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_. :param prices: Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
@ -2839,631 +2839,6 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
**kwargs, **kwargs,
).as_(self._bot) ).as_(self._bot)
def copy_to(
self,
chat_id: Union[int, str],
message_thread_id: Optional[int] = None,
caption: Optional[str] = None,
parse_mode: Optional[Union[str, Default]] = Default("parse_mode"),
caption_entities: Optional[List[MessageEntity]] = None,
show_caption_above_media: Optional[Union[bool, Default]] = Default(
"show_caption_above_media"
),
disable_notification: Optional[bool] = None,
protect_content: Optional[Union[bool, Default]] = Default("protect_content"),
reply_parameters: Optional[ReplyParameters] = None,
reply_markup: Optional[
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
] = None,
allow_sending_without_reply: Optional[bool] = None,
reply_to_message_id: Optional[int] = None,
**kwargs: Any,
) -> CopyMessage:
"""
Shortcut for method :class:`aiogram.methods.copy_message.CopyMessage`
will automatically fill method attributes:
- :code:`from_chat_id`
- :code:`message_id`
Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz :class:`aiogram.methods.poll.Poll` can be copied only if the value of the field *correct_option_id* is known to the bot. The method is analogous to the method :class:`aiogram.methods.forward_message.ForwardMessage`, but the copied message doesn't have a link to the original message. Returns the :class:`aiogram.types.message_id.MessageId` of the sent message on success.
Source: https://core.telegram.org/bots/api#copymessage
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
:param caption: New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
:param parse_mode: Mode for parsing entities in the new caption. See `formatting options <https://core.telegram.org/bots/api#formatting-options>`_ for more details.
:param caption_entities: A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of *parse_mode*
:param show_caption_above_media: Pass :code:`True`, if the caption must be shown above the message media. Ignored if a new caption isn't specified.
:param disable_notification: Sends the message `silently <https://telegram.org/blog/channels-2-0#silent-messages>`_. Users will receive a notification with no sound.
:param protect_content: Protects the contents of the sent message from forwarding and saving
:param reply_parameters: Description of the message to reply to
:param reply_markup: Additional interface options. A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_, `custom reply keyboard <https://core.telegram.org/bots/features#keyboards>`_, instructions to remove a reply keyboard or to force a reply from the user
:param allow_sending_without_reply: Pass :code:`True` if the message should be sent even if the specified replied-to message is not found
:param reply_to_message_id: If the message is a reply, ID of the original message
:return: instance of method :class:`aiogram.methods.copy_message.CopyMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import CopyMessage
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return CopyMessage(
from_chat_id=self.chat.id,
message_id=self.message_id,
chat_id=chat_id,
message_thread_id=message_thread_id,
caption=caption,
parse_mode=parse_mode,
caption_entities=caption_entities,
show_caption_above_media=show_caption_above_media,
disable_notification=disable_notification,
protect_content=protect_content,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
allow_sending_without_reply=allow_sending_without_reply,
reply_to_message_id=reply_to_message_id,
**kwargs,
).as_(self._bot)
def forward(
self,
chat_id: Union[int, str],
message_thread_id: Optional[int] = None,
disable_notification: Optional[bool] = None,
protect_content: Optional[Union[bool, Default]] = Default("protect_content"),
**kwargs: Any,
) -> ForwardMessage:
"""
Shortcut for method :class:`aiogram.methods.forward_message.ForwardMessage`
will automatically fill method attributes:
- :code:`from_chat_id`
- :code:`message_id`
Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent :class:`aiogram.types.message.Message` is returned.
Source: https://core.telegram.org/bots/api#forwardmessage
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
:param disable_notification: Sends the message `silently <https://telegram.org/blog/channels-2-0#silent-messages>`_. Users will receive a notification with no sound.
:param protect_content: Protects the contents of the forwarded message from forwarding and saving
:return: instance of method :class:`aiogram.methods.forward_message.ForwardMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import ForwardMessage
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return ForwardMessage(
from_chat_id=self.chat.id,
message_id=self.message_id,
chat_id=chat_id,
message_thread_id=message_thread_id,
disable_notification=disable_notification,
protect_content=protect_content,
**kwargs,
).as_(self._bot)
def edit_text(
self,
text: str,
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
parse_mode: Optional[Union[str, Default]] = Default("parse_mode"),
entities: Optional[List[MessageEntity]] = None,
link_preview_options: Optional[Union[LinkPreviewOptions, Default]] = Default(
"link_preview"
),
reply_markup: Optional[InlineKeyboardMarkup] = None,
disable_web_page_preview: Optional[Union[bool, Default]] = Default(
"link_preview_is_disabled"
),
**kwargs: Any,
) -> EditMessageText:
"""
Shortcut for method :class:`aiogram.methods.edit_message_text.EditMessageText`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to edit text and `game <https://core.telegram.org/bots/api#games>`_ 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. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within **48 hours** from the time they were sent.
Source: https://core.telegram.org/bots/api#editmessagetext
:param text: New text of the message, 1-4096 characters after entities parsing
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param parse_mode: Mode for parsing entities in the message text. See `formatting options <https://core.telegram.org/bots/api#formatting-options>`_ for more details.
:param entities: A JSON-serialized list of special entities that appear in message text, which can be specified instead of *parse_mode*
:param link_preview_options: Link preview generation options for the message
:param reply_markup: A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
:param disable_web_page_preview: Disables link previews for links in this message
:return: instance of method :class:`aiogram.methods.edit_message_text.EditMessageText`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import EditMessageText
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageText(
chat_id=self.chat.id,
message_id=self.message_id,
text=text,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
parse_mode=parse_mode,
entities=entities,
link_preview_options=link_preview_options,
reply_markup=reply_markup,
disable_web_page_preview=disable_web_page_preview,
**kwargs,
).as_(self._bot)
def edit_media(
self,
media: Union[
InputMediaAnimation,
InputMediaDocument,
InputMediaAudio,
InputMediaPhoto,
InputMediaVideo,
],
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
**kwargs: Any,
) -> EditMessageMedia:
"""
Shortcut for method :class:`aiogram.methods.edit_message_media.EditMessageMedia`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. 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. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within **48 hours** from the time they were sent.
Source: https://core.telegram.org/bots/api#editmessagemedia
:param media: A JSON-serialized object for a new media content of the message
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param reply_markup: A JSON-serialized object for a new `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
:return: instance of method :class:`aiogram.methods.edit_message_media.EditMessageMedia`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import EditMessageMedia
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageMedia(
chat_id=self.chat.id,
message_id=self.message_id,
media=media,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
**kwargs,
).as_(self._bot)
def edit_reply_markup(
self,
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = 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`
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. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within **48 hours** from the time they were sent.
Source: https://core.telegram.org/bots/api#editmessagereplymarkup
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param reply_markup: A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
: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
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageReplyMarkup(
chat_id=self.chat.id,
message_id=self.message_id,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
**kwargs,
).as_(self._bot)
def delete_reply_markup(
self,
business_connection_id: Optional[str] = None,
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. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within **48 hours** from the time they were sent.
Source: https://core.telegram.org/bots/api#editmessagereplymarkup
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
: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
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageReplyMarkup(
chat_id=self.chat.id,
message_id=self.message_id,
reply_markup=None,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
**kwargs,
).as_(self._bot)
def edit_live_location(
self,
latitude: float,
longitude: float,
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
live_period: Optional[int] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
**kwargs: Any,
) -> EditMessageLiveLocation:
"""
Shortcut for method :class:`aiogram.methods.edit_message_live_location.EditMessageLiveLocation`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to edit live location messages. A location can be edited until its *live_period* expires or editing is explicitly disabled by a call to :class:`aiogram.methods.stop_message_live_location.StopMessageLiveLocation`. 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#editmessagelivelocation
:param latitude: Latitude of new location
:param longitude: Longitude of new location
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param live_period: New period in seconds during which the location can be updated, starting from the message send date. If 0x7FFFFFFF is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current *live_period* by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then *live_period* remains unchanged
:param horizontal_accuracy: The radius of uncertainty for the location, measured in meters; 0-1500
:param heading: Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
:param proximity_alert_radius: The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
:param reply_markup: A JSON-serialized object for a new `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
:return: instance of method :class:`aiogram.methods.edit_message_live_location.EditMessageLiveLocation`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import EditMessageLiveLocation
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageLiveLocation(
chat_id=self.chat.id,
message_id=self.message_id,
latitude=latitude,
longitude=longitude,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
live_period=live_period,
horizontal_accuracy=horizontal_accuracy,
heading=heading,
proximity_alert_radius=proximity_alert_radius,
reply_markup=reply_markup,
**kwargs,
).as_(self._bot)
def stop_live_location(
self,
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
**kwargs: Any,
) -> StopMessageLiveLocation:
"""
Shortcut for method :class:`aiogram.methods.stop_message_live_location.StopMessageLiveLocation`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to stop updating a live location message before *live_period* expires. On success, if the 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#stopmessagelivelocation
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param reply_markup: A JSON-serialized object for a new `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
:return: instance of method :class:`aiogram.methods.stop_message_live_location.StopMessageLiveLocation`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import StopMessageLiveLocation
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return StopMessageLiveLocation(
chat_id=self.chat.id,
message_id=self.message_id,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
**kwargs,
).as_(self._bot)
def edit_caption(
self,
business_connection_id: Optional[str] = None,
inline_message_id: Optional[str] = None,
caption: Optional[str] = None,
parse_mode: Optional[Union[str, Default]] = Default("parse_mode"),
caption_entities: Optional[List[MessageEntity]] = None,
show_caption_above_media: Optional[Union[bool, Default]] = Default(
"show_caption_above_media"
),
reply_markup: Optional[InlineKeyboardMarkup] = None,
**kwargs: Any,
) -> EditMessageCaption:
"""
Shortcut for method :class:`aiogram.methods.edit_message_caption.EditMessageCaption`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to edit captions 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. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within **48 hours** from the time they were sent.
Source: https://core.telegram.org/bots/api#editmessagecaption
:param business_connection_id: Unique identifier of the business connection on behalf of which the message to be edited was sent
:param inline_message_id: Required if *chat_id* and *message_id* are not specified. Identifier of the inline message
:param caption: New caption of the message, 0-1024 characters after entities parsing
:param parse_mode: Mode for parsing entities in the message caption. See `formatting options <https://core.telegram.org/bots/api#formatting-options>`_ for more details.
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*
:param show_caption_above_media: Pass :code:`True`, if the caption must be shown above the message media. Supported only for animation, photo and video messages.
:param reply_markup: A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_.
:return: instance of method :class:`aiogram.methods.edit_message_caption.EditMessageCaption`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import EditMessageCaption
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return EditMessageCaption(
chat_id=self.chat.id,
message_id=self.message_id,
business_connection_id=business_connection_id,
inline_message_id=inline_message_id,
caption=caption,
parse_mode=parse_mode,
caption_entities=caption_entities,
show_caption_above_media=show_caption_above_media,
reply_markup=reply_markup,
**kwargs,
).as_(self._bot)
def delete(
self,
**kwargs: Any,
) -> DeleteMessage:
"""
Shortcut for method :class:`aiogram.methods.delete_message.DeleteMessage`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to delete a message, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Service messages about a supergroup, channel, or forum topic creation can't be deleted.
- A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots can delete incoming messages in private chats.
- Bots granted *can_post_messages* permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has *can_delete_messages* permission in a supergroup or a channel, it can delete any message there.
Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#deletemessage
:return: instance of method :class:`aiogram.methods.delete_message.DeleteMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeleteMessage
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return DeleteMessage(
chat_id=self.chat.id,
message_id=self.message_id,
**kwargs,
).as_(self._bot)
def pin(
self,
business_connection_id: Optional[str] = None,
disable_notification: Optional[bool] = None,
**kwargs: Any,
) -> PinChatMessage:
"""
Shortcut for method :class:`aiogram.methods.pin_chat_message.PinChatMessage`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#pinchatmessage
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be pinned
:param disable_notification: Pass :code:`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 and private chats.
:return: instance of method :class:`aiogram.methods.pin_chat_message.PinChatMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import PinChatMessage
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return PinChatMessage(
chat_id=self.chat.id,
message_id=self.message_id,
business_connection_id=business_connection_id,
disable_notification=disable_notification,
**kwargs,
).as_(self._bot)
def unpin(
self,
business_connection_id: Optional[str] = None,
**kwargs: Any,
) -> UnpinChatMessage:
"""
Shortcut for method :class:`aiogram.methods.unpin_chat_message.UnpinChatMessage`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unpinchatmessage
:param business_connection_id: Unique identifier of the business connection on behalf of which the message will be unpinned
:return: instance of method :class:`aiogram.methods.unpin_chat_message.UnpinChatMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import UnpinChatMessage
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return UnpinChatMessage(
chat_id=self.chat.id,
message_id=self.message_id,
business_connection_id=business_connection_id,
**kwargs,
).as_(self._bot)
def react(
self,
reaction: Optional[
List[Union[ReactionTypeEmoji, ReactionTypeCustomEmoji, ReactionTypePaid]]
] = None,
is_big: Optional[bool] = None,
**kwargs: Any,
) -> SetMessageReaction:
"""
Shortcut for method :class:`aiogram.methods.set_message_reaction.SetMessageReaction`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`message_id`
Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setmessagereaction
:param reaction: A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
:param is_big: Pass :code:`True` to set the reaction with a big animation
:return: instance of method :class:`aiogram.methods.set_message_reaction.SetMessageReaction`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetMessageReaction
assert (
self.chat is not None
), "This method can be used only if chat is present in the message."
return SetMessageReaction(
chat_id=self.chat.id,
message_id=self.message_id,
reaction=reaction,
is_big=is_big,
**kwargs,
).as_(self._bot)
def as_reply_parameters( def as_reply_parameters(
self, self,
allow_sending_without_reply: Optional[Union[bool, Default]] = Default( allow_sending_without_reply: Optional[Union[bool, Default]] = Default(

View file

@ -0,0 +1,150 @@
from typing import Any, Dict, Type, Union
import pytest
from aiogram.methods import (
SendAnimation,
SendAudio,
SendContact,
SendDice,
SendDocument,
SendGame,
SendInvoice,
SendLocation,
SendMediaGroup,
SendMessage,
SendPaidMedia,
SendPhoto,
SendPoll,
SendSticker,
SendVenue,
SendVideo,
SendVideoNote,
SendVoice,
)
from aiogram.types import Chat
from aiogram.types.inaccessible_message import InaccessibleMessage
from aiogram.types.message import ContentType
TEST_MESSAGE_UNKNOWN = InaccessibleMessage(
message_id=42,
chat=Chat(id=42, type="private"),
)
MESSAGES_AND_CONTENT_TYPES = [
[TEST_MESSAGE_UNKNOWN, ContentType.UNKNOWN],
]
class TestMessage:
@pytest.mark.parametrize(
"message,content_type",
MESSAGES_AND_CONTENT_TYPES,
)
def test_as_reply_parameters(self, message, content_type):
reply_parameters = message.as_reply_parameters()
assert reply_parameters.message_id == message.message_id
assert reply_parameters.chat_id == message.chat.id
@pytest.mark.parametrize(
"alias_for_method,kwargs,method_class",
[
["animation", dict(animation="animation"), SendAnimation],
["audio", dict(audio="audio"), SendAudio],
["contact", dict(phone_number="+000000000000", first_name="Test"), SendContact],
["document", dict(document="document"), SendDocument],
["game", dict(game_short_name="game"), SendGame],
[
"invoice",
dict(
title="title",
description="description",
payload="payload",
provider_token="provider_token",
start_parameter="start_parameter",
currency="currency",
prices=[],
),
SendInvoice,
],
["location", dict(latitude=0.42, longitude=0.42), SendLocation],
["media_group", dict(media=[]), SendMediaGroup],
["", dict(text="test"), SendMessage],
["photo", dict(photo="photo"), SendPhoto],
["poll", dict(question="Q?", options=[]), SendPoll],
["dice", dict(), SendDice],
["sticker", dict(sticker="sticker"), SendSticker],
["sticker", dict(sticker="sticker"), SendSticker],
[
"venue",
dict(
latitude=0.42,
longitude=0.42,
title="title",
address="address",
),
SendVenue,
],
["video", dict(video="video"), SendVideo],
["video_note", dict(video_note="video_note"), SendVideoNote],
["voice", dict(voice="voice"), SendVoice],
["paid_media", dict(media=[], star_count=42), SendPaidMedia],
],
)
@pytest.mark.parametrize("alias_type", ["reply", "answer"])
def test_reply_answer_aliases(
self,
alias_for_method: str,
alias_type: str,
kwargs: Dict[str, Any],
method_class: Type[
Union[
SendAnimation,
SendAudio,
SendContact,
SendDocument,
SendGame,
SendInvoice,
SendLocation,
SendMediaGroup,
SendMessage,
SendPhoto,
SendPoll,
SendSticker,
SendSticker,
SendVenue,
SendVideo,
SendVideoNote,
SendVoice,
SendPaidMedia,
]
],
):
message = InaccessibleMessage(
message_id=42, chat=Chat(id=42, type="private"),
)
alias_name = "_".join(item for item in [alias_type, alias_for_method] if item)
alias = getattr(message, alias_name)
assert callable(alias)
api_method = alias(**kwargs)
assert isinstance(api_method, method_class)
assert api_method.chat_id == message.chat.id
if alias_type == "reply":
assert api_method.reply_parameters
assert api_method.reply_parameters.message_id == message.message_id
assert api_method.reply_parameters.chat_id == message.chat.id
else:
assert api_method.reply_parameters is None
if hasattr(api_method, "reply_parameters"):
if alias_type == "reply":
assert api_method.reply_parameters is not None
assert api_method.reply_parameters.message_id == message.message_id
assert api_method.reply_parameters.chat_id == message.chat.id
else:
assert api_method.reply_parameters is None
for key, value in kwargs.items():
assert getattr(api_method, key) == value