Skip to content

Commit

Permalink
Add new get_stickers method
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Mar 16, 2024
1 parent 0bf78fa commit c5d6028
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def get_title_list(s: str) -> list:
send_chat_action
delete_messages
get_messages
get_stickers
get_media_group
get_chat_history
get_chat_history_count
Expand Down
2 changes: 2 additions & 0 deletions pyrogram/methods/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .get_discussion_replies_count import GetDiscussionRepliesCount
from .get_media_group import GetMediaGroup
from .get_messages import GetMessages
from .get_stickers import GetStickers
from .read_chat_history import ReadChatHistory
from .read_mentions import ReadMentions
from .read_reactions import ReadReactions
Expand Down Expand Up @@ -79,6 +80,7 @@ class Messages(
ForwardMessages,
GetMediaGroup,
GetMessages,
GetStickers,
SendAudio,
SendChatAction,
SendContact,
Expand Down
64 changes: 64 additions & 0 deletions pyrogram/methods/messages/get_stickers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.

import logging
from typing import List

import pyrogram
from pyrogram import raw
from pyrogram import types

log = logging.getLogger(__name__)


class GetStickers:
async def get_stickers(
self: "pyrogram.Client",
short_name: str
) -> List["types.Sticker"]:
"""Get all stickers from set by short name.
.. include:: /_includes/usable-by/users.rst
Parameters:
short_name (``str``):
Short name of the sticker set, serves as the unique identifier for the sticker set.
Returns:
List of :obj:`~pyrogram.types.Sticker`: A list of stickers is returned.
Example:
.. code-block:: python
# Get all stickers by short name
await app.get_stickers("short_name")
Raises:
ValueError: In case of invalid arguments.
"""
sticker_set = await self.invoke(
raw.functions.messages.GetStickerSet(
stickerset=raw.types.InputStickerSetShortName(short_name=short_name),
hash=0
)
)

return [
await types.Sticker._parse(self, doc, {type(a): a for a in doc.attributes})
for doc in sticker_set.documents
]

0 comments on commit c5d6028

Please sign in to comment.