From 9966bd92a5b786d8845f6b06395094be9b5dff3d Mon Sep 17 00:00:00 2001 From: wulan17 Date: Mon, 10 Apr 2023 19:35:05 +0700 Subject: [PATCH] PyroFork: Add GetStickerSet methods and StickerSet types Signed-off-by: wulan17 --- compiler/docs/template/methods.rst | 13 +++ pyrogram/methods/__init__.py | 2 + pyrogram/methods/stickers/__init__.py | 24 +++++ pyrogram/methods/stickers/get_sticker_set.py | 54 +++++++++++ pyrogram/types/messages_and_media/__init__.py | 3 +- .../types/messages_and_media/stickerset.py | 89 +++++++++++++++++++ 6 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/stickers/__init__.py create mode 100644 pyrogram/methods/stickers/get_sticker_set.py create mode 100644 pyrogram/types/messages_and_media/stickerset.py diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst index f76e249d..4a1a1896 100644 --- a/compiler/docs/template/methods.rst +++ b/compiler/docs/template/methods.rst @@ -73,6 +73,19 @@ Chats {chats} +Stickers +----- + +.. autosummary:: + :nosignatures: + + {stickers} + +.. toctree:: + :hidden: + + {stickers} + Users ----- diff --git a/pyrogram/methods/__init__.py b/pyrogram/methods/__init__.py index ea71f6b1..544d19c7 100644 --- a/pyrogram/methods/__init__.py +++ b/pyrogram/methods/__init__.py @@ -25,6 +25,7 @@ from .decorators import Decorators from .invite_links import InviteLinks from .messages import Messages from .password import Password +from .stickers import Stickers from .users import Users from .utilities import Utilities @@ -36,6 +37,7 @@ class Methods( Contacts, Password, Chats, + Stickers, Users, Messages, Decorators, diff --git a/pyrogram/methods/stickers/__init__.py b/pyrogram/methods/stickers/__init__.py new file mode 100644 index 00000000..ffd9d918 --- /dev/null +++ b/pyrogram/methods/stickers/__init__.py @@ -0,0 +1,24 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from .get_sticker_set import GetStickerSet + +class Stickers( + GetStickerSet, +): + pass diff --git a/pyrogram/methods/stickers/get_sticker_set.py b/pyrogram/methods/stickers/get_sticker_set.py new file mode 100644 index 00000000..d42eb1f5 --- /dev/null +++ b/pyrogram/methods/stickers/get_sticker_set.py @@ -0,0 +1,54 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class GetStickerSet: + async def get_sticker_set( + self: "pyrogram.Client", + set_short_name: str + ) -> "types.StickerSet": + """Get info about a stickerset. + + .. include:: /_includes/usable-by/users-bot.rst + + Parameters: + set_short_name (``str``): + Stickerset shortname. + + Returns: + :obj:`~pyrogram.types.StickerSet`: On success, the StickerSet information is returned. + + Example: + .. code-block:: python + + await app.get_sticker_set("mypack1") + """ + r = await self.invoke( + raw.functions.messages.GetStickerSet( + stickerset=raw.types.InputStickerSetShortName(short_name=set_short_name), + hash=0 + ) + ) + + return types.StickerSet._parse(r.set) diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 54dfd560..f6e93801 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -30,6 +30,7 @@ from .poll import Poll from .poll_option import PollOption from .reaction import Reaction from .sticker import Sticker +from .stickerset import StickerSet from .stripped_thumbnail import StrippedThumbnail from .thumbnail import Thumbnail from .venue import Venue @@ -42,6 +43,6 @@ from .message_reactions import MessageReactions __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", - "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", + "StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", "WebAppData", "MessageReactions" ] diff --git a/pyrogram/types/messages_and_media/stickerset.py b/pyrogram/types/messages_and_media/stickerset.py new file mode 100644 index 00000000..cdda41d5 --- /dev/null +++ b/pyrogram/types/messages_and_media/stickerset.py @@ -0,0 +1,89 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import List, Optional, Union + +import pyrogram +from pyrogram import raw +from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource +from ..object import Object + + +class StickerSet(Object): + """One size of a photo or a file/sticker thumbnail. + + Parameters: + id (``Integer``): + Identifier for this stickerset. + + title (``String``): + Title of stickerset. + + short_name (``String``): + Short name of stickerset, used when sharing stickerset using stickerset deep links. + + count (``Integer``): + Number of stickers in stickerset. + + masks (``Boolean``): + Is this a mask stickerset. + + animated (``Boolean``): + Is this a animated stickerset. + + videos (``Boolean``): + Is this a videos stickerset. + + emojis (``Boolean``): + Is this a emojis stickerset. + """ + + def __init__( + self, + *, + id: int, + title: str, + short_name: str, + count: int, + masks: bool = None, + animated: bool = None, + videos: bool = None, + emojis: bool = None + ): + self.id = id + self.title = title + self.short_name = short_name + self.count = count + self.masks = masks + self.animated = animated + self.videos = videos + self.emojis = emojis + + @staticmethod + def _parse(stickerset: "raw.types.StickerSet") -> "StickerSet": + + return StickerSet( + id=getattr(stickerset,"id", None), + title=getattr(stickerset,"title", None), + short_name=getattr(stickerset,"short_name", None), + count=getattr(stickerset,"count", None), + masks=getattr(stickerset,"masks", None), + animated=getattr(stickerset,"animated", None), + videos=getattr(stickerset,"videos", None), + emojis=getattr(stickerset,"emojis", None) + )