mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
PyroFork: Add Sticker methods and types
Signed-off-by: wulan17 <wulan17@nusantararom.org> PyroFork: Add CreateStickerSet Methods Signed-off-by: wulan17 <wulan17@nusantararom.org> PyroFork: Add AddStickerToSet Methods Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
ea33dc43a4
commit
d91cf7f120
9 changed files with 402 additions and 1 deletions
|
|
@ -267,6 +267,12 @@ def pyrogram_api():
|
||||||
get_default_emoji_statuses
|
get_default_emoji_statuses
|
||||||
set_emoji_status
|
set_emoji_status
|
||||||
""",
|
""",
|
||||||
|
stickers="""
|
||||||
|
Stickers
|
||||||
|
add_sticker_to_set
|
||||||
|
create_sticker_set
|
||||||
|
get_sticker_set
|
||||||
|
""",
|
||||||
invite_links="""
|
invite_links="""
|
||||||
Invite Links
|
Invite Links
|
||||||
get_chat_invite_link
|
get_chat_invite_link
|
||||||
|
|
@ -422,6 +428,7 @@ def pyrogram_api():
|
||||||
Location
|
Location
|
||||||
Venue
|
Venue
|
||||||
Sticker
|
Sticker
|
||||||
|
StickerSet
|
||||||
Game
|
Game
|
||||||
WebPage
|
WebPage
|
||||||
Poll
|
Poll
|
||||||
|
|
|
||||||
13
compiler/docs/template/methods.rst
vendored
13
compiler/docs/template/methods.rst
vendored
|
|
@ -73,6 +73,19 @@ Chats
|
||||||
|
|
||||||
{chats}
|
{chats}
|
||||||
|
|
||||||
|
Stickers
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. autosummary::
|
||||||
|
:nosignatures:
|
||||||
|
|
||||||
|
{stickers}
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:hidden:
|
||||||
|
|
||||||
|
{stickers}
|
||||||
|
|
||||||
Users
|
Users
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ from .decorators import Decorators
|
||||||
from .invite_links import InviteLinks
|
from .invite_links import InviteLinks
|
||||||
from .messages import Messages
|
from .messages import Messages
|
||||||
from .password import Password
|
from .password import Password
|
||||||
|
from .stickers import Stickers
|
||||||
from .users import Users
|
from .users import Users
|
||||||
from .utilities import Utilities
|
from .utilities import Utilities
|
||||||
|
|
||||||
|
|
@ -36,6 +37,7 @@ class Methods(
|
||||||
Contacts,
|
Contacts,
|
||||||
Password,
|
Password,
|
||||||
Chats,
|
Chats,
|
||||||
|
Stickers,
|
||||||
Users,
|
Users,
|
||||||
Messages,
|
Messages,
|
||||||
Decorators,
|
Decorators,
|
||||||
|
|
|
||||||
28
pyrogram/methods/stickers/__init__.py
Normal file
28
pyrogram/methods/stickers/__init__.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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
|
||||||
85
pyrogram/methods/stickers/add_sticker_to_set.py
Normal file
85
pyrogram/methods/stickers/add_sticker_to_set.py
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
122
pyrogram/methods/stickers/create_sticker_set.py
Normal file
122
pyrogram/methods/stickers/create_sticker_set.py
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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_<bot_username>".
|
||||||
|
<bot_username> 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)
|
||||||
54
pyrogram/methods/stickers/get_sticker_set.py
Normal file
54
pyrogram/methods/stickers/get_sticker_set.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
@ -30,6 +30,7 @@ from .poll import Poll
|
||||||
from .poll_option import PollOption
|
from .poll_option import PollOption
|
||||||
from .reaction import Reaction
|
from .reaction import Reaction
|
||||||
from .sticker import Sticker
|
from .sticker import Sticker
|
||||||
|
from .stickerset import StickerSet
|
||||||
from .stripped_thumbnail import StrippedThumbnail
|
from .stripped_thumbnail import StrippedThumbnail
|
||||||
from .thumbnail import Thumbnail
|
from .thumbnail import Thumbnail
|
||||||
from .venue import Venue
|
from .venue import Venue
|
||||||
|
|
@ -42,6 +43,6 @@ from .message_reactions import MessageReactions
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"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"
|
"Reaction", "WebAppData", "MessageReactions"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
89
pyrogram/types/messages_and_media/stickerset.py
Normal file
89
pyrogram/types/messages_and_media/stickerset.py
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue