diff --git a/pyrogram/methods/stickers/add_sticker_to_set.py b/pyrogram/methods/stickers/add_sticker_to_set.py index 6d14a793c..2f853c04a 100644 --- a/pyrogram/methods/stickers/add_sticker_to_set.py +++ b/pyrogram/methods/stickers/add_sticker_to_set.py @@ -22,13 +22,17 @@ import pyrogram from pyrogram import raw from pyrogram import types -from pyrogram.file_id import FileId +from pyrogram import utils +from pyrogram.file_id import FileId, FileType + +from typing import Union class AddStickerToSet: async def add_sticker_to_set( self: "pyrogram.Client", set_short_name: str, sticker: str, + user_id: Union[int, str] = None, emoji: str = "🤔", ) -> "types.StickerSet": """Add a sticker to stickerset. @@ -41,7 +45,16 @@ async def add_sticker_to_set( sticker (``str``): sticker to add. - Pass a file_id as string to send a file that exists on the Telegram servers. + Pass a file_id as string to add a sticker that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get a sticker from the Internet, + pass a file path as string to upload a new sticker that exists on your local machine, or + pass a binary file-like object with its attribute ".name" set for in-memory uploads. + + user_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the Stickerset owner. + For you yourself you can simply use "me" or "self" (users only). + required for bots. + default to "me". emoji (``str``, *optional*): Associated emoji. @@ -55,11 +68,19 @@ async def add_sticker_to_set( await app.add_sticker_to_set("mypack1", "AsJiasp") """ - file = None if isinstance(sticker, str): + if self.me.is_bot and user_id is None: + raise ValueError("user_id is required for bots") if os.path.isfile(sticker) or re.match("^https?://", sticker): - raise ValueError(f"file_id is invalid!") + document = await self.send_document( + user_id or "me", + sticker, + force_document=True, + disable_notification=True + ) + media = utils.get_input_media_from_file_id(document, FileType.DOCUMENT) + _ = await document.delete() else: decoded = FileId.decode(sticker) media = raw.types.InputDocument( @@ -68,7 +89,16 @@ async def add_sticker_to_set( file_reference=decoded.file_reference ) else: - raise ValueError(f"file_id is invalid!") + if self.me.is_bot and user_id is None: + raise ValueError("user_id is required for bots") + document = await self.send_document( + user_id or "me", + sticker, + force_document=True, + disable_notification=True + ) + media = utils.get_input_media_from_file_id(document, FileType.DOCUMENT) + _ = await document.delete() r = await self.invoke( raw.functions.stickers.AddStickerToSet( diff --git a/pyrogram/methods/stickers/create_sticker_set.py b/pyrogram/methods/stickers/create_sticker_set.py index 6365276d3..eb1559f40 100644 --- a/pyrogram/methods/stickers/create_sticker_set.py +++ b/pyrogram/methods/stickers/create_sticker_set.py @@ -23,16 +23,17 @@ import pyrogram from pyrogram import raw from pyrogram import types -from pyrogram.file_id import FileId +from pyrogram import utils +from pyrogram.file_id import FileId, FileType class CreateStickerSet: async def create_sticker_set( self: "pyrogram.Client", - user_id: Union[int, str], title: str, short_name: str, sticker: str, + user_id: Union[int, str] = None, emoji: str = "🤔", masks: bool = None ) -> Optional["types.Message"]: @@ -41,10 +42,6 @@ async def create_sticker_set( .. 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 @@ -58,6 +55,12 @@ async def create_sticker_set( sticker to add. Pass a file_id as string to send a file that exists on the Telegram servers. + user_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the Stickerset owner. + For you yourself you can simply use "me" or "self" (users only). + required for bots. + default to "me". + emoji (``str``, *optional*): Associated emoji. default to "🤔" @@ -71,14 +74,22 @@ async def create_sticker_set( 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 self.me.is_bot and user_id is None: + raise ValueError("user_id is required for bots") if isinstance(sticker, str): if os.path.isfile(sticker) or re.match("^https?://", sticker): - raise ValueError(f"file_id is invalid!") + document = await self.send_document( + user_id or "me", + sticker, + force_document=True, + disable_notification=True + ) + media = utils.get_input_media_from_file_id(document, FileType.DOCUMENT) + _ = await document.delete() else: decoded = FileId.decode(sticker) media = raw.types.InputDocument( @@ -87,11 +98,18 @@ async def create_sticker_set( file_reference=decoded.file_reference ) else: - raise ValueError(f"file_id is invalid!") + document = await self.send_document( + user_id or "me", + sticker, + force_document=True, + disable_notification=True + ) + media = utils.get_input_media_from_file_id(document, FileType.DOCUMENT) + _ = await document.delete() r = await self.invoke( raw.functions.stickers.CreateStickerSet( - user_id=await self.resolve_peer(user_id), + user_id=await self.resolve_peer(user_id or "me"), title=title, short_name=short_name, stickers=[