From 64c580d5fd938ec42df625cb273dd6e29dd832c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarc=C3=ADsio=20Eduardo=20Moreira=20Crocomo?= Date: Sat, 27 Jun 2020 00:37:47 -0300 Subject: [PATCH 1/3] WIP: upload_sticker_file and create_new_sticker_set. --- roboto/bot.py | 21 +++++++++++++++++++++ roboto/request_types.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/roboto/bot.py b/roboto/bot.py index 16411f3..b035fa8 100644 --- a/roboto/bot.py +++ b/roboto/bot.py @@ -102,6 +102,7 @@ StopPollRequest, UnbanChatMemberRequest, UnpinChatMessageRequest, + UploadStickerFileRequest, json_serialize, maybe_json_serialize, ) @@ -1874,6 +1875,26 @@ async def get_sticker_set(self, name: StickerSetName) -> StickerSet: ), ) + async def upload_sticker_file( + self, user_id: UserID, png_sticker: InputFile, + ) -> File: + """uploadStickerFile API method. + + Args: + user_id: User identifier of the sticker file owner. + png_sticker: PNG image for the sticker. Must obey the file size and image + dimension restrictions set by Telegram. + """ + + request = UploadStickerFileRequest(user_id, png_sticker) + + return from_json_like( + File, + await make_request( + self.session, HTTPMethod.POST, '/uploadStickerFile', request, + ), + ) + __all__ = [ 'BotAPI', diff --git a/roboto/request_types.py b/roboto/request_types.py index 6e640b1..127faea 100644 --- a/roboto/request_types.py +++ b/roboto/request_types.py @@ -17,6 +17,7 @@ InputMedia, InputMediaPhoto, InputMediaVideo, + MaskPosition, MessageID, ParseMode, PollType, @@ -628,3 +629,37 @@ class GetStickerSetRequest: """Parameters for getting a sticker set.""" name: str + + +@dataclass(frozen=True) +class UploadStickerFileRequest: + """Parameters for uploading a file for a sticker.""" + + user_id: UserID + png_sticker: InputFile + + +@dataclass(frozen=True) +class CreateNewPngStickerSetRequest: + """Parameters for creating a new sticker set with a PNG sticker.""" + + user_id: UserID + name: str + title: str + png_sticker: InputFile + emojis: str + contains_masks: Optional[bool] = None + mask_position: Optional[MaskPosition] = None + + +@dataclass(frozen=True) +class CreateNewTgsStickerSetRequest: + """Parameters for creating a new sticker set with a TGS (animated) sticker.""" + + user_id: UserID + name: str + title: str + tgs_sticker: InputFile + emojis: str + contains_masks: Optional[bool] = None + mask_position: Optional[MaskPosition] = None From 08a86f2734506ac5868b6748a2d9eb6c277e7a62 Mon Sep 17 00:00:00 2001 From: Gabriel Simonetto Date: Thu, 9 Jul 2020 21:28:44 -0300 Subject: [PATCH 2/3] Force isort and pylint version to allow commit checks --- tasks.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tasks.py b/tasks.py index 54246a8..e4974be 100644 --- a/tasks.py +++ b/tasks.py @@ -135,9 +135,9 @@ def install_dev_tools( 'black', 'flake8', 'flake8-bugbear', - 'isort', + 'isort==4.3.21', 'mypy', - 'pylint', + 'pylint==2.5.3', 'pylint-quotes', *extra_deps, ], @@ -217,9 +217,7 @@ def format( # pylint: disable=redefined-builtin return [ execute(['black', '-q', *black_check_flag, *subject], raise_error=False), - execute( - ['isort', '-rc', '-y', '-q', *isort_check_flag, *subject], raise_error=False - ), + execute(['isort', '-q', *isort_check_flag, *subject], raise_error=False), ] From 0e5d9b88eb8b25163d24e77b9e1669716bf3008d Mon Sep 17 00:00:00 2001 From: Gabriel Simonetto Date: Sat, 25 Jul 2020 12:44:05 -0300 Subject: [PATCH 3/3] Add set_sticker_set_thumb (missing tests) --- roboto/bot.py | 26 ++++++++++++++++++++++++++ roboto/request_types.py | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/roboto/bot.py b/roboto/bot.py index b035fa8..97ae329 100644 --- a/roboto/bot.py +++ b/roboto/bot.py @@ -97,6 +97,7 @@ SetChatStickerSetRequest, SetChatTitleRequest, SetMyCommandsRequest, + SetStickerSetThumbRequest, StopInlineMessageLiveLocationRequest, StopMessageLiveLocationRequest, StopPollRequest, @@ -1895,6 +1896,31 @@ async def upload_sticker_file( ), ) + async def set_sticker_set_thumb( + self, + name: str, + user_id: UserID, + thumb: Optional[Union[InputFile, FileID]] = None, + ) -> bool: + """setStickerSetThumb API method. + + Args: + name: Sticker set name + user_id: User identifier of the sticker set owner. + thumb: An FileID of a file already uploaded to Telegram servers, + or an InputFile for the thumbnail. + Must obey the file size and image dimension + restrictions set by Telegram. + See the documentation on InputFile. + """ + + request = SetStickerSetThumbRequest(name, user_id, thumb,) + + return from_json_like( + bool, + await make_multipart_request(self.session, '/setStickerSetThumb', request), + ) + __all__ = [ 'BotAPI', diff --git a/roboto/request_types.py b/roboto/request_types.py index 127faea..d1de395 100644 --- a/roboto/request_types.py +++ b/roboto/request_types.py @@ -663,3 +663,12 @@ class CreateNewTgsStickerSetRequest: emojis: str contains_masks: Optional[bool] = None mask_position: Optional[MaskPosition] = None + + +@dataclass(frozen=True) +class SetStickerSetThumbRequest: + """Parameters for setting a thumb of a sticker set.""" + + name: str + user_id: UserID + thumb: Optional[Union[InputFile, FileID]] = None