From 33fd25060c6e333daeba68ae83b830942a81d296 Mon Sep 17 00:00:00 2001 From: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com> Date: Sat, 17 Dec 2022 00:02:14 +0300 Subject: [PATCH] Add links to "Working with Files and Media" wiki page from docstrings (#3423) Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Co-authored-by: Viicos <65306057+Viicos@users.noreply.github.com> Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com> --- docs/source/conf.py | 4 +++ telegram/_bot.py | 36 ++++++++++++------- telegram/_files/file.py | 4 +++ telegram/_files/inputmedia.py | 12 +++++++ telegram/_inline/inlinequeryresultaudio.py | 2 ++ .../_inline/inlinequeryresultcachedaudio.py | 2 ++ .../inlinequeryresultcacheddocument.py | 2 ++ .../_inline/inlinequeryresultcachedgif.py | 2 ++ .../inlinequeryresultcachedmpeg4gif.py | 2 ++ .../_inline/inlinequeryresultcachedphoto.py | 2 ++ .../_inline/inlinequeryresultcachedsticker.py | 2 ++ .../_inline/inlinequeryresultcachedvideo.py | 2 ++ .../_inline/inlinequeryresultcachedvoice.py | 2 ++ telegram/_inline/inlinequeryresultdocument.py | 2 ++ telegram/_inline/inlinequeryresultgif.py | 2 ++ telegram/_inline/inlinequeryresultmpeg4gif.py | 2 ++ telegram/_inline/inlinequeryresultphoto.py | 2 ++ telegram/_inline/inlinequeryresultvideo.py | 2 ++ telegram/_inline/inlinequeryresultvoice.py | 2 ++ telegram/_message.py | 19 +++++++++- 20 files changed, 92 insertions(+), 13 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 336e43aa246..8fd6dcf4113 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -44,11 +44,15 @@ "sphinx.ext.napoleon", "sphinx.ext.intersphinx", "sphinx.ext.linkcode", + "sphinx.ext.extlinks", "sphinx_paramlinks", "sphinxcontrib.mermaid", "sphinx_search.extension", ] +# For shorter links to Wiki in docstrings +extlinks = {"wiki": ("https://github.com/python-telegram-bot/python-telegram-bot/wiki/%s", "%s")} + # Use intersphinx to reference the python builtin library docs intersphinx_mapping = { "python": ("https://docs.python.org/3", None), diff --git a/telegram/_bot.py b/telegram/_bot.py index 95a9b23a022..040d29285a6 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -909,7 +909,8 @@ async def send_photo( """Use this method to send photos. .. seealso:: :meth:`telegram.Message.reply_photo`, :meth:`telegram.Chat.send_photo`, - :meth:`telegram.User.send_photo` + :meth:`telegram.User.send_photo`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1018,7 +1019,8 @@ async def send_audio( For sending voice messages, use the :meth:`send_voice` method instead. .. seealso:: :meth:`telegram.Message.reply_audio`, :meth:`telegram.Chat.send_audio`, - :meth:`telegram.User.send_audio` + :meth:`telegram.User.send_audio`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1139,7 +1141,8 @@ async def send_document( changed in the future. .. seealso:: :meth:`telegram.Message.reply_document`, :meth:`telegram.Chat.send_document`, - :meth:`telegram.User.send_document` + :meth:`telegram.User.send_document`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1248,7 +1251,8 @@ async def send_sticker( Use this method to send static ``.WEBP``, animated ``.TGS``, or video ``.WEBM`` stickers. .. seealso:: :meth:`telegram.Message.reply_sticker`, :meth:`telegram.Chat.send_sticker`, - :meth:`telegram.User.send_sticker` + :meth:`telegram.User.send_sticker`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1343,7 +1347,8 @@ async def send_video( changed by Telegram. .. seealso:: :meth:`telegram.Message.reply_video`, :meth:`telegram.Chat.send_video`, - :meth:`telegram.User.send_video` + :meth:`telegram.User.send_video`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1468,7 +1473,8 @@ async def send_video_note( .. seealso:: :meth:`telegram.Message.reply_video_note`, :meth:`telegram.Chat.send_video_note`, - :meth:`telegram.User.send_video_note` + :meth:`telegram.User.send_video_note`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1590,7 +1596,8 @@ async def send_animation( .. seealso:: :meth:`telegram.Message.reply_animation`, :meth:`telegram.Chat.send_animation`, - :meth:`telegram.User.send_animation` + :meth:`telegram.User.send_animation`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1715,7 +1722,8 @@ async def send_voice( sent as files. .. seealso:: :meth:`telegram.Message.reply_voice`, :meth:`telegram.Chat.send_voice`, - :meth:`telegram.User.send_voice` + :meth:`telegram.User.send_voice`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -1824,7 +1832,8 @@ async def send_media_group( .. seealso:: :meth:`telegram.Message.reply_media_group`, :meth:`telegram.Chat.send_media_group`, - :meth:`telegram.User.send_media_group` + :meth:`telegram.User.send_media_group`, + :wiki:`Working with Files and Media ` Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| @@ -2664,7 +2673,8 @@ async def answer_inline_query( :paramref:`telegram.InlineQuery.answer.auto_pagination` set to :obj:`True`, which will take care of passing the correct value. - .. seealso:: :meth:`telegram.InlineQuery.answer` + .. seealso:: :meth:`telegram.InlineQuery.answer`, + :wiki:`Working with Files and Media ` Args: inline_query_id (:obj:`str`): Unique identifier for the answered query. @@ -2812,7 +2822,8 @@ async def get_file( :meth:`telegram.Document.get_file`, :meth:`telegram.PassportFile.get_file`, :meth:`telegram.PhotoSize.get_file`, :meth:`telegram.Sticker.get_file`, :meth:`telegram.Video.get_file`, :meth:`telegram.VideoNote.get_file`, - :meth:`telegram.Voice.get_file` + :meth:`telegram.Voice.get_file`, + :wiki:`Working with Files and Media ` Args: file_id (:obj:`str` | :class:`telegram.Animation` | :class:`telegram.Audio` | \ @@ -3304,7 +3315,8 @@ async def edit_message_media( |editreplymarkup| .. seealso:: :meth:`telegram.Message.edit_media`, - :meth:`telegram.CallbackQuery.edit_message_media` + :meth:`telegram.CallbackQuery.edit_message_media`, + :wiki:`Working with Files and Media ` Args: media (:class:`telegram.InputMedia`): An object for a new media content diff --git a/telegram/_files/file.py b/telegram/_files/file.py index dbcfe2b4ca8..251b1f73975 100644 --- a/telegram/_files/file.py +++ b/telegram/_files/file.py @@ -141,6 +141,8 @@ async def download_to_drive( original file in order to decrypt the file without changing the existing one in-place. + .. seealso:: :wiki:`Working with Files and Media ` + .. versionchanged:: 20.0 * :paramref:`custom_path` parameter now also accepts :class:`pathlib.Path` as argument. @@ -224,6 +226,8 @@ async def download_to_memory( :obj:`io.BufferedIOBase`, the file contents will be saved to that object using the :obj:`out.write` method. + .. seealso:: :wiki:`Working with Files and Media ` + .. versionadded:: 20.0 Args: diff --git a/telegram/_files/inputmedia.py b/telegram/_files/inputmedia.py index bf40b1ea21c..ed7bbaf6305 100644 --- a/telegram/_files/inputmedia.py +++ b/telegram/_files/inputmedia.py @@ -44,6 +44,8 @@ class InputMedia(TelegramObject): Added arguments and attributes :attr:`type`, :attr:`media`, :attr:`caption`, :attr:`caption_entities`, :paramref:`parse_mode`. + .. seealso:: :wiki:`Working with Files and Media ` + Args: media_type (:obj:`str`): Type of media that the instance represents. media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \ @@ -115,6 +117,8 @@ class InputMediaAnimation(InputMedia): width, height and duration from that video, unless otherwise specified with the optional arguments. + .. seealso:: :wiki:`Working with Files and Media ` + Args: media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \ :class:`telegram.Animation`): File to send. |fileinputnopath| @@ -208,6 +212,8 @@ def __init__( class InputMediaPhoto(InputMedia): """Represents a photo to be sent. + .. seealso:: :wiki:`Working with Files and Media ` + Args: media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \ :class:`telegram.PhotoSize`): File to send. |fileinputnopath| @@ -273,6 +279,8 @@ def __init__( class InputMediaVideo(InputMedia): """Represents a video to be sent. + .. seealso:: :wiki:`Working with Files and Media ` + Note: * When using a :class:`telegram.Video` for the :attr:`media` attribute, it will take the width, height and duration from that video, unless otherwise specified with the optional @@ -380,6 +388,8 @@ def __init__( class InputMediaAudio(InputMedia): """Represents an audio file to be treated as music to be sent. + .. seealso:: :wiki:`Working with Files and Media ` + Note: When using a :class:`telegram.Audio` for the :attr:`media` attribute, it will take the duration, performer and title from that video, unless otherwise specified with the @@ -479,6 +489,8 @@ def __init__( class InputMediaDocument(InputMedia): """Represents a general file to be sent. + .. seealso:: :wiki:`Working with Files and Media ` + Args: media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \ :class:`telegram.Document`): File to send. |fileinputnopath| diff --git a/telegram/_inline/inlinequeryresultaudio.py b/telegram/_inline/inlinequeryresultaudio.py index 1c1bbe6d24c..7713bf70a3f 100644 --- a/telegram/_inline/inlinequeryresultaudio.py +++ b/telegram/_inline/inlinequeryresultaudio.py @@ -37,6 +37,8 @@ class InlineQueryResultAudio(InlineQueryResult): Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the audio. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedaudio.py b/telegram/_inline/inlinequeryresultcachedaudio.py index 370a9883313..de1f3525dc2 100644 --- a/telegram/_inline/inlinequeryresultcachedaudio.py +++ b/telegram/_inline/inlinequeryresultcachedaudio.py @@ -37,6 +37,8 @@ class InlineQueryResultCachedAudio(InlineQueryResult): file will be sent by the user. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the audio. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcacheddocument.py b/telegram/_inline/inlinequeryresultcacheddocument.py index 74cda79aca8..a274da888c5 100644 --- a/telegram/_inline/inlinequeryresultcacheddocument.py +++ b/telegram/_inline/inlinequeryresultcacheddocument.py @@ -37,6 +37,8 @@ class InlineQueryResultCachedDocument(InlineQueryResult): by the user with an optional caption. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the file. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedgif.py b/telegram/_inline/inlinequeryresultcachedgif.py index 2f5038d3a3e..ac9427b2986 100644 --- a/telegram/_inline/inlinequeryresultcachedgif.py +++ b/telegram/_inline/inlinequeryresultcachedgif.py @@ -38,6 +38,8 @@ class InlineQueryResultCachedGif(InlineQueryResult): use :attr:`input_message_content` to send a message with specified content instead of the animation. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedmpeg4gif.py b/telegram/_inline/inlinequeryresultcachedmpeg4gif.py index 1857113832f..b033bc3aa76 100644 --- a/telegram/_inline/inlinequeryresultcachedmpeg4gif.py +++ b/telegram/_inline/inlinequeryresultcachedmpeg4gif.py @@ -38,6 +38,8 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): optional caption. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the animation. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedphoto.py b/telegram/_inline/inlinequeryresultcachedphoto.py index 30855e7129c..69f8c55e37d 100644 --- a/telegram/_inline/inlinequeryresultcachedphoto.py +++ b/telegram/_inline/inlinequeryresultcachedphoto.py @@ -38,6 +38,8 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): :attr:`input_message_content` to send a message with the specified content instead of the photo. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedsticker.py b/telegram/_inline/inlinequeryresultcachedsticker.py index f4a121e6cab..76e31c0b7d3 100644 --- a/telegram/_inline/inlinequeryresultcachedsticker.py +++ b/telegram/_inline/inlinequeryresultcachedsticker.py @@ -35,6 +35,8 @@ class InlineQueryResultCachedSticker(InlineQueryResult): be sent by the user. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the sticker. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedvideo.py b/telegram/_inline/inlinequeryresultcachedvideo.py index d82ca22a896..d3f244905d4 100644 --- a/telegram/_inline/inlinequeryresultcachedvideo.py +++ b/telegram/_inline/inlinequeryresultcachedvideo.py @@ -38,6 +38,8 @@ class InlineQueryResultCachedVideo(InlineQueryResult): :attr:`input_message_content` to send a message with the specified content instead of the video. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultcachedvoice.py b/telegram/_inline/inlinequeryresultcachedvoice.py index 19c5f4051bf..3ab072b310d 100644 --- a/telegram/_inline/inlinequeryresultcachedvoice.py +++ b/telegram/_inline/inlinequeryresultcachedvoice.py @@ -37,6 +37,8 @@ class InlineQueryResultCachedVoice(InlineQueryResult): message will be sent by the user. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the voice message. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultdocument.py b/telegram/_inline/inlinequeryresultdocument.py index e262b38c4dd..8d0e231db32 100644 --- a/telegram/_inline/inlinequeryresultdocument.py +++ b/telegram/_inline/inlinequeryresultdocument.py @@ -38,6 +38,8 @@ class InlineQueryResultDocument(InlineQueryResult): specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultgif.py b/telegram/_inline/inlinequeryresultgif.py index 9bbc236478c..31fe7603d6f 100644 --- a/telegram/_inline/inlinequeryresultgif.py +++ b/telegram/_inline/inlinequeryresultgif.py @@ -37,6 +37,8 @@ class InlineQueryResultGif(InlineQueryResult): the user with optional caption. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the animation. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultmpeg4gif.py b/telegram/_inline/inlinequeryresultmpeg4gif.py index 5656da94a24..06d71ec3096 100644 --- a/telegram/_inline/inlinequeryresultmpeg4gif.py +++ b/telegram/_inline/inlinequeryresultmpeg4gif.py @@ -38,6 +38,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): use :attr:`input_message_content` to send a message with the specified content instead of the animation. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultphoto.py b/telegram/_inline/inlinequeryresultphoto.py index 4517e7acfe1..63d15c0e99b 100644 --- a/telegram/_inline/inlinequeryresultphoto.py +++ b/telegram/_inline/inlinequeryresultphoto.py @@ -37,6 +37,8 @@ class InlineQueryResultPhoto(InlineQueryResult): caption. Alternatively, you can use :attr:`input_message_content` to send a message with the specified content instead of the photo. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultvideo.py b/telegram/_inline/inlinequeryresultvideo.py index 5fd617f7550..0fb7c6fd4ef 100644 --- a/telegram/_inline/inlinequeryresultvideo.py +++ b/telegram/_inline/inlinequeryresultvideo.py @@ -42,6 +42,8 @@ class InlineQueryResultVideo(InlineQueryResult): If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using :attr:`input_message_content`. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_inline/inlinequeryresultvoice.py b/telegram/_inline/inlinequeryresultvoice.py index 6a4d52109cc..12de92aa6c1 100644 --- a/telegram/_inline/inlinequeryresultvoice.py +++ b/telegram/_inline/inlinequeryresultvoice.py @@ -38,6 +38,8 @@ class InlineQueryResultVoice(InlineQueryResult): :attr:`input_message_content` to send a message with the specified content instead of the voice message. + .. seealso:: :wiki:`Working with Files and Media ` + Args: id (:obj:`str`): Unique identifier for this result, :tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`- diff --git a/telegram/_message.py b/telegram/_message.py index 3f84539f4bf..3119c345ce9 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -349,33 +349,48 @@ class Message(TelegramObject): audio (:class:`telegram.Audio`): Optional. Message is an audio file, information about the file. + + .. seealso:: :wiki:`Working with Files and Media ` document (:class:`telegram.Document`): Optional. Message is a general file, information about the file. + + .. seealso:: :wiki:`Working with Files and Media ` animation (:class:`telegram.Animation`): Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set. + + .. seealso:: :wiki:`Working with Files and Media ` game (:class:`telegram.Game`): Optional. Message is a game, information about the game. photo (Tuple[:class:`telegram.PhotoSize`]): Optional. Message is a photo, available sizes of the photo. This list is empty if the message does not contain a photo. + .. seealso:: :wiki:`Working with Files and Media ` + .. versionchanged:: 20.0 |tupleclassattrs| sticker (:class:`telegram.Sticker`): Optional. Message is a sticker, information about the sticker. + + .. seealso:: :wiki:`Working with Files and Media ` video (:class:`telegram.Video`): Optional. Message is a video, information about the video. + + .. seealso:: :wiki:`Working with Files and Media ` voice (:class:`telegram.Voice`): Optional. Message is a voice message, information about the file. + + .. seealso:: :wiki:`Working with Files and Media ` video_note (:class:`telegram.VideoNote`): Optional. Message is a video note, information about the video message. + + .. seealso:: :wiki:`Working with Files and Media ` new_chat_members (Tuple[:class:`telegram.User`]): Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). This list is empty if the message does not contain new chat members. .. versionchanged:: 20.0 |tupleclassattrs| - caption (:obj:`str`): Optional. Caption for the animation, audio, document, photo, video or voice, 0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters. contact (:class:`telegram.Contact`): Optional. Message is a shared contact, information @@ -841,6 +856,8 @@ def effective_attachment( Otherwise :obj:`None` is returned. + .. seealso:: :wiki:`Working with Files and Media ` + .. versionchanged:: 20.0 :attr:`dice`, :attr:`passport_data` and :attr:`poll` are now also considered to be an attachment.