diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 4a311aa0..f387d515 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -267,6 +267,12 @@ def pyrogram_api(): get_default_emoji_statuses set_emoji_status """, + stickers=""" + Stickers + add_sticker_to_set + create_sticker_set + get_sticker_set + """, invite_links=""" Invite Links get_chat_invite_link @@ -422,6 +428,7 @@ def pyrogram_api(): Location Venue Sticker + StickerSet Game WebPage Poll diff --git a/compiler/docs/template/methods.rst b/compiler/docs/template/methods.rst index 35123f6a..868dd16e 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..19c6163c --- /dev/null +++ b/pyrogram/methods/stickers/__init__.py @@ -0,0 +1,28 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from .add_sticker_to_set import AddStickerToSet +from .create_sticker_set import CreateStickerSet +from .get_sticker_set import GetStickerSet + +class Stickers( + AddStickerToSet, + CreateStickerSet, + GetStickerSet +): + pass diff --git a/pyrogram/methods/stickers/add_sticker_to_set.py b/pyrogram/methods/stickers/add_sticker_to_set.py new file mode 100644 index 00000000..7706172e --- /dev/null +++ b/pyrogram/methods/stickers/add_sticker_to_set.py @@ -0,0 +1,85 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +import os +import re +from typing import Union + +import pyrogram +from pyrogram import raw +from pyrogram import types + +class AddStickerToSet: + async def add_sticker_to_set( + self: "pyrogram.Client", + set_short_name: str, + sticker: str, + emoji: str = "🤔", + ) -> "types.StickerSet": + """Add a sticker to stickerset. + + .. include:: /_includes/usable-by/bots.rst + + Parameters: + set_short_name (``str``): + Stickerset shortname. + + sticker (``str``): + sticker to add. + Pass a file_id as string to send a file that exists on the Telegram servers. + + emoji (``str``, *optional*): + Associated emoji. + default to "🤔" + + Returns: + :obj:`~pyrogram.types.StickerSet`: On success, the StickerSet information is returned. + + Example: + .. code-block:: python + + await app.add_sticker_to_set("mypack1", "AsJiasp") + """ + file = None + + if isinstance(sticker, str): + if os.path.isfile(sticker) or re.match("^https?://", sticker): + raise ValueError(f"file_id is invalid!") + else: + decoded = FileId.decode(sticker) + media = raw.types.InputDocument( + id=decoded.media_id, + access_hash=decoded.access_hash, + file_reference=decoded.file_reference + ) + else: + raise ValueError(f"file_id is invalid!") + + r = await self.invoke( + raw.functions.stickers.AddStickerToSet( + stickerset=raw.types.InputStickerSetShortName(short_name=set_short_name), + sticker=[ + raw.types.InputStickerSetItem( + document=media, + emoji=emoji + ) + ] + ) + ) + + return types.StickerSet._parse(r.set) diff --git a/pyrogram/methods/stickers/create_sticker_set.py b/pyrogram/methods/stickers/create_sticker_set.py new file mode 100644 index 00000000..744ca034 --- /dev/null +++ b/pyrogram/methods/stickers/create_sticker_set.py @@ -0,0 +1,122 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +import os +import re +from typing import Union, Optional + +import pyrogram +from pyrogram import raw +from pyrogram import types +from pyrogram.file_id import FileId + + +class CreateStickerSet: + async def create_sticker_set( + self: "pyrogram.Client", + user_id: Union[int, str], + title: str, + short_name: str, + sticker: str, + emoji: str = "🤔", + masks: bool = None, + animated: bool = None, + videos: bool = None, + emojis: bool = None + ) -> Optional["types.Message"]: + """Create a new stickerset. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + user_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the Stickerset owner. + For you yourself you can simply use "me" or "self" (users only). + + title (``str``): + Stickerset name, 1-64 chars + + short_name (``str``, *optional*): + Short name of sticker set, to be used in sticker deep links. + Can contain only english letters, digits and underscores. + Must begin with a letter, can't contain consecutive underscores and, if called by a bot, must end in "_by_". + is case insensitive. 1-64 characters. + + sticker (``str``): + sticker to add. + Pass a file_id as string to send a file that exists on the Telegram servers. + + emoji (``str``, *optional*): + Associated emoji. + default to "🤔" + + masks (``bool``, *optional*): + Whether this is a mask stickerset. + + animated (``bool``, *optional*): + Whether this is a animated stickerset. + + videos (``bool``, *optional*): + Whether this is a videos stickerset. + + emojis (``bool``, *optional*): + Whether this is a emojis stickerset. + + Returns: + :obj:`~pyrogram.types.StickerSet` | ``None``: On success, the StickerSet is returned. + + Example: + .. code-block:: python + + # Send document by uploading from local file + await app.create_sticker_set("me", "My First Pack", "myfirstpack", "AAjjHjk") + """ + file = None + + if isinstance(sticker, str): + if os.path.isfile(sticker) or re.match("^https?://", sticker): + raise ValueError(f"file_id is invalid!") + else: + decoded = FileId.decode(sticker) + media = raw.types.InputDocument( + id=decoded.media_id, + access_hash=decoded.access_hash, + file_reference=decoded.file_reference + ) + else: + raise ValueError(f"file_id is invalid!") + + r = await self.invoke( + raw.functions.stickers.CreateStickerSet( + user_id=await self.resolve_peer(user_id), + title=title, + short_name=short_name, + stickers=[ + raw.types.InputStickerSetItem( + document=media, + emoji=emoji + ) + ], + masks=masks, + animated=animated, + videos=videos, + emojis=emojis + ) + ) + + return types.StickerSet._parse(r.set) diff --git a/pyrogram/methods/stickers/get_sticker_set.py b/pyrogram/methods/stickers/get_sticker_set.py new file mode 100644 index 00000000..0ef9898b --- /dev/null +++ b/pyrogram/methods/stickers/get_sticker_set.py @@ -0,0 +1,54 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. 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-bots.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..385b1fe5 --- /dev/null +++ b/pyrogram/types/messages_and_media/stickerset.py @@ -0,0 +1,89 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. 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): + """A stickerset. + + 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) + )