diff --git a/aiogram/types/animation.py b/aiogram/types/animation.py index b08089c1..21e8c995 100644 --- a/aiogram/types/animation.py +++ b/aiogram/types/animation.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Animation(base.TelegramObject, mixins.Downloadable): @@ -18,7 +21,39 @@ class Animation(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + width: base.Integer, + height: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + width=width, + height=height, + duration=duration, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py index 1657c9cc..36599dc2 100644 --- a/aiogram/types/audio.py +++ b/aiogram/types/audio.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Audio(base.TelegramObject, mixins.Downloadable): @@ -18,4 +21,36 @@ class Audio(base.TelegramObject, mixins.Downloadable): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + duration: base.Integer, + performer: typing.Optional[base.String] = None, + title: typing.Optional[base.String] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + duration=duration, + performer=performer, + title=title, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + thumbnail=thumbnail, + ) diff --git a/aiogram/types/document.py b/aiogram/types/document.py index c3d19fa9..10adb657 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -1,8 +1,11 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize from ..utils import helper +from ..utils.deprecated import warn_deprecated class Document(base.TelegramObject, mixins.Downloadable): @@ -13,11 +16,37 @@ class Document(base.TelegramObject, mixins.Downloadable): """ file_id: base.String = fields.Field() file_unique_id: base.String = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) + @property def mime_base(self) -> str: base_type, _, _ = self.mime_type.partition('/') diff --git a/aiogram/types/inline_query_result.py b/aiogram/types/inline_query_result.py index da09db9d..14ceb8bc 100644 --- a/aiogram/types/inline_query_result.py +++ b/aiogram/types/inline_query_result.py @@ -5,6 +5,7 @@ from . import fields from .inline_keyboard import InlineKeyboardMarkup from .input_message_content import InputMessageContent from .message_entity import MessageEntity +from ..utils.deprecated import warn_deprecated class InlineQueryResult(base.TelegramObject): @@ -42,9 +43,14 @@ class InlineQueryResultArticle(InlineQueryResult): url: base.String = fields.Field() hide_url: base.Boolean = fields.Field() description: base.String = fields.Field() - thumb_url: base.String = fields.Field() - thumb_width: base.Integer = fields.Field() - thumb_height: base.Integer = fields.Field() + # Deprecated fields + thumb_url: base.String = fields.Field() # Deprecated, use thumbnail_url instead + thumb_width: base.Integer = fields.Field() # Deprecated, use thumbnail_width instead + thumb_height: base.Integer = fields.Field() # Deprecated, use thumbnail_height instead + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__(self, *, id: base.String, @@ -54,14 +60,37 @@ class InlineQueryResultArticle(InlineQueryResult): url: typing.Optional[base.String] = None, hide_url: typing.Optional[base.Boolean] = None, description: typing.Optional[base.String] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None): - super(InlineQueryResultArticle, self).__init__(id=id, title=title, - input_message_content=input_message_content, - reply_markup=reply_markup, url=url, hide_url=hide_url, - description=description, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height) + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None): + + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + "thumb_width parameter is deprecated, please use thumbnail_width." + ) + if thumb_height and not thumbnail_height: + warn_deprecated( + "thumb_height parameter is deprecated, please use thumbnail_height." + ) + thumbnail_height = thumb_height + + super().__init__(id=id, title=title, + input_message_content=input_message_content, + reply_markup=reply_markup, url=url, hide_url=hide_url, + description=description, thumb_url=thumb_url, + thumb_width=thumb_width, thumb_height=thumb_height, + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height) class InlineQueryResultPhoto(InlineQueryResult): @@ -76,7 +105,10 @@ class InlineQueryResultPhoto(InlineQueryResult): """ type: base.String = fields.Field(alias='type', default='photo') photo_url: base.String = fields.Field() + # Deprecated field thumb_url: base.String = fields.Field() + # New field + thumbnail_url: base.String = fields.Field() photo_width: base.Integer = fields.Field() photo_height: base.Integer = fields.Field() title: base.String = fields.Field() @@ -89,7 +121,8 @@ class InlineQueryResultPhoto(InlineQueryResult): *, id: base.String, photo_url: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, photo_width: typing.Optional[base.Integer] = None, photo_height: typing.Optional[base.Integer] = None, title: typing.Optional[base.String] = None, @@ -100,8 +133,17 @@ class InlineQueryResultPhoto(InlineQueryResult): reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url argument is required") + super().__init__( - id=id, photo_url=photo_url, thumb_url=thumb_url, + id=id, photo_url=photo_url, thumbnail_url=thumbnail_url, photo_width=photo_width, photo_height=photo_height, title=title, description=description, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, @@ -124,8 +166,12 @@ class InlineQueryResultGif(InlineQueryResult): gif_width: base.Integer = fields.Field() gif_height: base.Integer = fields.Field() gif_duration: base.Integer = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() thumb_mime_type: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_mime_type: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) @@ -138,7 +184,10 @@ class InlineQueryResultGif(InlineQueryResult): gif_width: typing.Optional[base.Integer] = None, gif_height: typing.Optional[base.Integer] = None, gif_duration: typing.Optional[base.Integer] = None, - thumb_url: typing.Optional[base.String] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_mime_type: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_mime_type: typing.Optional[base.String] = None, title: typing.Optional[base.String] = None, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, @@ -146,9 +195,22 @@ class InlineQueryResultGif(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url and thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + if not thumbnail_mime_type and thumb_mime_type: + warn_deprecated( + "thumb_mime_type parameter is deprecated, please use thumbnail_mime_type." + ) + thumbnail_mime_type = thumb_mime_type + super().__init__( id=id, gif_url=gif_url, gif_width=gif_width, gif_height=gif_height, - gif_duration=gif_duration, thumb_url=thumb_url, title=title, + gif_duration=gif_duration, + thumbnail_url=thumbnail_url, thumbnail_mime_type=thumbnail_mime_type, + title=title, caption=caption, parse_mode=parse_mode, reply_markup=reply_markup, caption_entities=caption_entities, input_message_content=input_message_content, @@ -170,8 +232,12 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): mpeg4_width: base.Integer = fields.Field() mpeg4_height: base.Integer = fields.Field() mpeg4_duration: base.Integer = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() thumb_mime_type: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_mime_type: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) @@ -181,7 +247,10 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): *, id: base.String, mpeg4_url: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_mime_type: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_mime_type: typing.Optional[base.String] = None, mpeg4_width: typing.Optional[base.Integer] = None, mpeg4_height: typing.Optional[base.Integer] = None, mpeg4_duration: typing.Optional[base.Integer] = None, @@ -192,10 +261,26 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url is required") + if not thumbnail_mime_type and thumb_mime_type: + warn_deprecated( + "thumb_mime_type parameter is deprecated, please use thumbnail_mime_type." + ) + thumbnail_mime_type = thumb_mime_type + + super().__init__( id=id, mpeg4_url=mpeg4_url, mpeg4_width=mpeg4_width, mpeg4_height=mpeg4_height, mpeg4_duration=mpeg4_duration, - thumb_url=thumb_url, title=title, caption=caption, + thumbnail_url=thumbnail_url, thumbnail_mime_type=thumbnail_mime_type, + title=title, caption=caption, parse_mode=parse_mode, reply_markup=reply_markup, caption_entities=caption_entities, input_message_content=input_message_content, @@ -218,7 +303,10 @@ class InlineQueryResultVideo(InlineQueryResult): type: base.String = fields.Field(alias='type', default='video') video_url: base.String = fields.Field() mime_type: base.String = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() video_width: base.Integer = fields.Field() @@ -233,7 +321,8 @@ class InlineQueryResultVideo(InlineQueryResult): id: base.String, video_url: base.String, mime_type: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, title: base.String, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, @@ -245,8 +334,17 @@ class InlineQueryResultVideo(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url is required") + super().__init__( - id=id, video_url=video_url, mime_type=mime_type, thumb_url=thumb_url, + id=id, video_url=video_url, mime_type=mime_type, thumbnail_url=thumbnail_url, title=title, caption=caption, video_width=video_width, video_height=video_height, video_duration=video_duration, description=description, parse_mode=parse_mode, @@ -357,9 +455,14 @@ class InlineQueryResultDocument(InlineQueryResult): mime_type: base.String = fields.Field() description: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__( self, @@ -374,17 +477,36 @@ class InlineQueryResultDocument(InlineQueryResult): description: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, title=title, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, document_url=document_url, mime_type=mime_type, description=description, reply_markup=reply_markup, input_message_content=input_message_content, - thumb_url=thumb_url, thumb_width=thumb_width, - thumb_height=thumb_height, + thumbnail_url=thumbnail_url, thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, ) @@ -407,9 +529,14 @@ class InlineQueryResultLocation(InlineQueryResult): heading: typing.Optional[base.Integer] = fields.Field() proximity_alert_radius: typing.Optional[base.Integer] = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__(self, *, id: base.String, @@ -422,10 +549,29 @@ class InlineQueryResultLocation(InlineQueryResult): proximity_alert_radius: typing.Optional[base.Integer] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, latitude=latitude, @@ -437,9 +583,9 @@ class InlineQueryResultLocation(InlineQueryResult): proximity_alert_radius=proximity_alert_radius, reply_markup=reply_markup, input_message_content=input_message_content, - thumb_url=thumb_url, - thumb_width=thumb_width, - thumb_height=thumb_height + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, ) @@ -465,9 +611,14 @@ class InlineQueryResultVenue(InlineQueryResult): google_place_id: base.String = fields.Field() google_place_type: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__( self, @@ -483,17 +634,36 @@ class InlineQueryResultVenue(InlineQueryResult): google_place_type: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, latitude=latitude, longitude=longitude, title=title, address=address, foursquare_id=foursquare_id, foursquare_type=foursquare_type, google_place_id=google_place_id, google_place_type=google_place_type, reply_markup=reply_markup, - input_message_content=input_message_content, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height, + input_message_content=input_message_content, thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, thumbnail_height=thumbnail_height, ) @@ -515,9 +685,14 @@ class InlineQueryResultContact(InlineQueryResult): last_name: base.String = fields.Field() vcard: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() foursquare_type: base.String = fields.Field() def __init__(self, *, @@ -527,15 +702,36 @@ class InlineQueryResultContact(InlineQueryResult): last_name: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, foursquare_type: typing.Optional[base.String] = None): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super(InlineQueryResultContact, self).__init__(id=id, phone_number=phone_number, first_name=first_name, last_name=last_name, reply_markup=reply_markup, - input_message_content=input_message_content, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height, + input_message_content=input_message_content, + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, foursquare_type=foursquare_type) diff --git a/aiogram/types/input_media.py b/aiogram/types/input_media.py index 876a8f41..decd4714 100644 --- a/aiogram/types/input_media.py +++ b/aiogram/types/input_media.py @@ -6,6 +6,7 @@ from . import base from . import fields from .input_file import InputFile from .message_entity import MessageEntity +from ..utils.deprecated import warn_deprecated ATTACHMENT_PREFIX = 'attach://' @@ -112,7 +113,8 @@ class InputMediaAnimation(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String] = None, + thumb: typing.Union[base.InputFile, base.String] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, width: base.Integer = None, height: base.Integer = None, @@ -122,8 +124,14 @@ class InputMediaAnimation(InputMedia): has_spoiler: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) + super().__init__( - type='animation', media=media, thumb=thumb, caption=caption, width=width, + type='animation', media=media, thumbnail=thumbnail, caption=caption, width=width, height=height, duration=duration, parse_mode=parse_mode, caption_entities=caption_entities, has_spoiler=has_spoiler, conf=kwargs, ) @@ -139,15 +147,21 @@ class InputMediaDocument(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String, None] = None, caption: base.String = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, disable_content_type_detection: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='document', media=media, thumb=thumb, caption=caption, + type='document', media=media, thumbnail=thumbnail, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, disable_content_type_detection=disable_content_type_detection, conf=kwargs, @@ -168,7 +182,8 @@ class InputMediaAudio(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String] = None, + thumb: typing.Union[base.InputFile, base.String] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, duration: base.Integer = None, performer: base.String = None, @@ -177,8 +192,13 @@ class InputMediaAudio(InputMedia): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='audio', media=media, thumb=thumb, caption=caption, + type='audio', media=media, thumbnail=thumbnail, caption=caption, duration=duration, performer=performer, title=title, parse_mode=parse_mode, caption_entities=caption_entities, conf=kwargs, ) @@ -216,6 +236,8 @@ class InputMediaVideo(InputMedia): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() + thumb: typing.Union[base.InputFile, base.String] = fields.Field() # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = fields.Field() supports_streaming: base.Boolean = fields.Field() has_spoiler: typing.Optional[base.Boolean] = fields.Field() @@ -223,6 +245,7 @@ class InputMediaVideo(InputMedia): self, media: base.InputFile, thumb: typing.Union[base.InputFile, base.String] = None, + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, width: base.Integer = None, height: base.Integer = None, @@ -233,8 +256,13 @@ class InputMediaVideo(InputMedia): has_spoiler: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='video', media=media, thumb=thumb, caption=caption, + type='video', media=media, thumbnail=thumbnail, caption=caption, width=width, height=height, duration=duration, parse_mode=parse_mode, caption_entities=caption_entities, supports_streaming=supports_streaming, has_spoiler=has_spoiler, conf=kwargs @@ -346,7 +374,7 @@ class MediaGroup(base.TelegramObject): caption_entities=caption_entities) self.attach(audio) - def attach_document(self, document: typing.Union[InputMediaDocument, base.InputFile], + def attach_document(self, document: typing.Union[InputMediaDocument, base.InputFile], thumb: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, @@ -362,7 +390,7 @@ class MediaGroup(base.TelegramObject): :param disable_content_type_detection: """ if not isinstance(document, InputMedia): - document = InputMediaDocument(media=document, thumb=thumb, caption=caption, + document = InputMediaDocument(media=document, thumb=thumb, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, disable_content_type_detection=disable_content_type_detection) self.attach(document) @@ -386,7 +414,7 @@ class MediaGroup(base.TelegramObject): def attach_video(self, video: typing.Union[InputMediaVideo, base.InputFile], thumb: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, - width: base.Integer = None, height: base.Integer = None, + width: base.Integer = None, height: base.Integer = None, duration: base.Integer = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, supports_streaming: base.Boolean = None): diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index 476a1e1e..ff2d50e4 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -1,9 +1,12 @@ +import typing + from . import base from . import fields from . import mixins from .mask_position import MaskPosition from .photo_size import PhotoSize from .file import File +from ..utils.deprecated import warn_deprecated class Sticker(base.TelegramObject, mixins.Downloadable): @@ -20,6 +23,7 @@ class Sticker(base.TelegramObject, mixins.Downloadable): is_animated: base.Boolean = fields.Field() is_video: base.Boolean = fields.Field() thumb: PhotoSize = fields.Field(base=PhotoSize) + thumbnail: PhotoSize = fields.Field(base=PhotoSize) emoji: base.String = fields.Field() set_name: base.String = fields.Field() premium_animation: File = fields.Field(base=File) @@ -28,6 +32,49 @@ class Sticker(base.TelegramObject, mixins.Downloadable): needs_repainting: base.Boolean = fields.Field() file_size: base.Integer = fields.Field() + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + type: base.String, + width: base.Integer, + height: base.Integer, + is_animated: base.Boolean, + is_video: base.Boolean, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + emoji: typing.Optional[base.String] = None, + set_name: typing.Optional[base.String] = None, + premium_animation: typing.Optional[File] = None, + mask_position: typing.Optional[MaskPosition] = None, + custom_emoji_id: typing.Optional[base.String] = None, + needs_repainting: typing.Optional[base.Boolean] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if thumb is not None: + warn_deprecated( + "The 'thumb' parameter is deprecated, use 'thumbnail' instead." + ) + thumbnail = thumb + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + type=type, + width=width, + height=height, + is_animated=is_animated, + is_video=is_video, + thumbnail=thumbnail, + emoji=emoji, + set_name=set_name, + premium_animation=premium_animation, + mask_position=mask_position, + custom_emoji_id=custom_emoji_id, + needs_repainting=needs_repainting, + file_size=file_size, + ) + async def set_position_in_set(self, position: base.Integer) -> base.Boolean: """ Use this method to move a sticker in a set created by the bot to a specific position. diff --git a/aiogram/types/sticker_set.py b/aiogram/types/sticker_set.py index 809094c2..16f31d78 100644 --- a/aiogram/types/sticker_set.py +++ b/aiogram/types/sticker_set.py @@ -4,6 +4,7 @@ from . import base from . import fields from .photo_size import PhotoSize from .sticker import Sticker +from ..utils.deprecated import warn_deprecated class StickerSet(base.TelegramObject): @@ -19,4 +20,34 @@ class StickerSet(base.TelegramObject): is_video: base.Boolean = fields.Field() contains_masks: base.Boolean = fields.Field() # Deprecated stickers: typing.List[Sticker] = fields.ListField(base=Sticker) - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) + + def __init__( + self, + name: base.String, + title: base.String, + sticker_type: base.String, + is_animated: base.Boolean, + is_video: base.Boolean, + contains_masks: typing.Optional[base.Boolean] = None, + stickers: typing.List[Sticker] = None, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + name=name, + title=title, + sticker_type=sticker_type, + is_animated=is_animated, + is_video=is_video, + contains_masks=contains_masks, + stickers=stickers, + thumbnail=thumbnail, + ) diff --git a/aiogram/types/video.py b/aiogram/types/video.py index d4958761..58a7b0e3 100644 --- a/aiogram/types/video.py +++ b/aiogram/types/video.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Video(base.TelegramObject, mixins.Downloadable): @@ -15,7 +18,39 @@ class Video(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + width: base.Integer, + height: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + width=width, + height=height, + duration=duration, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py index 8702faae..5ab7e825 100644 --- a/aiogram/types/video_note.py +++ b/aiogram/types/video_note.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class VideoNote(base.TelegramObject, mixins.Downloadable): @@ -14,5 +17,31 @@ class VideoNote(base.TelegramObject, mixins.Downloadable): file_unique_id: base.String = fields.Field() length: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + length: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + length=length, + duration=duration, + thumbnail=thumbnail, + file_size=file_size, + )