mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added shortcut
This commit is contained in:
parent
7634587fa4
commit
3a4ca057fe
4 changed files with 91 additions and 4 deletions
|
|
@ -174,6 +174,11 @@ reply_voice:
|
|||
code: *assert-chat
|
||||
fill: *fill-reply
|
||||
|
||||
answer_paid_media:
|
||||
method: sendPaidMedia
|
||||
code: *assert-chat
|
||||
fill: *fill-answer
|
||||
|
||||
copy_to:
|
||||
method: copyMessage
|
||||
code: *assert-chat
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from aiogram.utils.text_decorations import (
|
|||
html_decoration,
|
||||
markdown_decoration,
|
||||
)
|
||||
from . import InputPaidMediaPhoto, InputPaidMediaVideo
|
||||
|
||||
from ..client.default import Default
|
||||
from ..enums import ContentType
|
||||
|
|
@ -47,6 +48,7 @@ if TYPE_CHECKING:
|
|||
SetMessageReaction,
|
||||
StopMessageLiveLocation,
|
||||
UnpinChatMessage,
|
||||
SendPaidMedia,
|
||||
)
|
||||
from .animation import Animation
|
||||
from .audio import Audio
|
||||
|
|
@ -4099,3 +4101,69 @@ class Message(MaybeInaccessibleMessage):
|
|||
is_big=is_big,
|
||||
**kwargs,
|
||||
).as_(self._bot)
|
||||
|
||||
def answer_paid_media(
|
||||
self,
|
||||
star_count: int,
|
||||
media: List[Union[InputPaidMediaPhoto, InputPaidMediaVideo]],
|
||||
caption: Optional[str] = None,
|
||||
parse_mode: Optional[str] = None,
|
||||
caption_entities: Optional[List[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
disable_notification: Optional[bool] = None,
|
||||
protect_content: Optional[bool] = None,
|
||||
reply_parameters: Optional[ReplyParameters] = None,
|
||||
reply_markup: Optional[
|
||||
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
|
||||
] = None,
|
||||
**kwargs: Any,
|
||||
) -> SendPaidMedia:
|
||||
"""
|
||||
Shortcut for method :class:`aiogram.methods.send_paid_media.SendPaidMedia`
|
||||
will automatically fill method attributes:
|
||||
|
||||
- :code:`chat_id`
|
||||
- :code:`message_thread_id`
|
||||
- :code:`business_connection_id`
|
||||
|
||||
Use this method to send paid media to channel chats. On success, the sent :class:`aiogram.types.message.Message` is returned.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#sendpaidmedia
|
||||
|
||||
:param star_count: The number of Telegram Stars that must be paid to buy access to the media
|
||||
:param media: A JSON-serialized array describing the media to be sent; up to 10 items
|
||||
:param caption: Media caption, 0-1024 characters after entities parsing
|
||||
:param parse_mode: Mode for parsing entities in the media 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
|
||||
: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
|
||||
:return: instance of method :class:`aiogram.methods.send_paid_media.SendPaidMedia`
|
||||
"""
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
# This method was auto-generated via `butcher`
|
||||
|
||||
from aiogram.methods import SendPaidMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
|
||||
return SendPaidMedia(
|
||||
chat_id=self.chat.id,
|
||||
message_thread_id=self.message_thread_id if self.is_topic_message else None,
|
||||
business_connection_id=self.business_connection_id,
|
||||
star_count=star_count,
|
||||
media=media,
|
||||
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,
|
||||
**kwargs,
|
||||
).as_(self._bot)
|
||||
|
|
|
|||
|
|
@ -43,3 +43,9 @@ As reply into Webhook in handler
|
|||
.. code-block:: python
|
||||
|
||||
return SendPaidMedia(...)
|
||||
|
||||
|
||||
As shortcut from received object
|
||||
--------------------------------
|
||||
|
||||
- :meth:`aiogram.types.message.Message.answer_paid_media`
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ from aiogram.methods import (
|
|||
StopMessageLiveLocation,
|
||||
TelegramMethod,
|
||||
UnpinChatMessage,
|
||||
SendPaidMedia,
|
||||
)
|
||||
from aiogram.types import (
|
||||
UNSET_PARSE_MODE,
|
||||
|
|
@ -798,6 +799,7 @@ class TestMessage:
|
|||
["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"])
|
||||
|
|
@ -825,9 +827,14 @@ class TestMessage:
|
|||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
SendPaidMedia,
|
||||
]
|
||||
],
|
||||
):
|
||||
if alias_for_method == "paid_media" and alias_type == "reply":
|
||||
# Replies should be completely reworked
|
||||
pytest.skip("Reply alias for paid media is not implemented yet.")
|
||||
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
)
|
||||
|
|
@ -840,10 +847,11 @@ class TestMessage:
|
|||
assert isinstance(api_method, method_class)
|
||||
|
||||
assert api_method.chat_id == message.chat.id
|
||||
if alias_type == "reply":
|
||||
assert api_method.reply_to_message_id == message.message_id
|
||||
else:
|
||||
assert api_method.reply_to_message_id is None
|
||||
if hasattr(api_method, "reply_to_message_id"):
|
||||
if alias_type == "reply":
|
||||
assert api_method.reply_to_message_id == message.message_id
|
||||
else:
|
||||
assert api_method.reply_to_message_id is None
|
||||
|
||||
for key, value in kwargs.items():
|
||||
assert getattr(api_method, key) == value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue