Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set sticker set thumb #43

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions roboto/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@
SetChatStickerSetRequest,
SetChatTitleRequest,
SetMyCommandsRequest,
SetStickerSetThumbRequest,
StopInlineMessageLiveLocationRequest,
StopMessageLiveLocationRequest,
StopPollRequest,
UnbanChatMemberRequest,
UnpinChatMessageRequest,
UploadStickerFileRequest,
json_serialize,
maybe_json_serialize,
)
Expand Down Expand Up @@ -1874,6 +1876,51 @@ 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,
),
)

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',
Expand Down
44 changes: 44 additions & 0 deletions roboto/request_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
InputMedia,
InputMediaPhoto,
InputMediaVideo,
MaskPosition,
MessageID,
ParseMode,
PollType,
Expand Down Expand Up @@ -628,3 +629,46 @@ 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


@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
8 changes: 3 additions & 5 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down Expand Up @@ -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),
]


Expand Down