From feff7cd29dd08c968710f770eb8850ea97d609fa Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 1 Jun 2024 00:43:26 +0300 Subject: [PATCH] Add get_available_effects method --- compiler/docs/compiler.py | 2 + pyrogram/methods/messages/__init__.py | 2 + .../methods/messages/get_available_effects.py | 59 +++++++++++++ .../messages/get_custom_emoji_stickers.py | 2 +- pyrogram/methods/messages/get_stickers.py | 10 ++- pyrogram/types/messages_and_media/__init__.py | 2 + .../messages_and_media/available_effect.py | 88 +++++++++++++++++++ 7 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 pyrogram/methods/messages/get_available_effects.py create mode 100644 pyrogram/types/messages_and_media/available_effect.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 25618865..8d14d0eb 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -175,6 +175,7 @@ def pyrogram_api(): edit_inline_reply_markup send_chat_action delete_messages + get_available_effects get_messages get_scheduled_messages get_stickers @@ -476,6 +477,7 @@ def pyrogram_api(): Photo Thumbnail Audio + AvailableEffect Document Animation Video diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index 447389c0..be7e8897 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -29,6 +29,7 @@ from .edit_message_media import EditMessageMedia from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages +from .get_available_effects import GetAvailableEffects from .get_chat_history import GetChatHistory from .get_chat_history_count import GetChatHistoryCount from .get_custom_emoji_stickers import GetCustomEmojiStickers @@ -80,6 +81,7 @@ class Messages( EditMessageMedia, EditMessageText, ForwardMessages, + GetAvailableEffects, GetMediaGroup, GetMessages, GetScheduledMessages, diff --git a/pyrogram/methods/messages/get_available_effects.py b/pyrogram/methods/messages/get_available_effects.py new file mode 100644 index 00000000..fc853781 --- /dev/null +++ b/pyrogram/methods/messages/get_available_effects.py @@ -0,0 +1,59 @@ +# 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 . + +import logging +from typing import List + +import pyrogram +from pyrogram import raw +from pyrogram import types + +log = logging.getLogger(__name__) + + +class GetAvailableEffects: + async def get_available_effects( + self: "pyrogram.Client" + ) -> List["types.AvailableEffect"]: + """Get all available effects. + + .. include:: /_includes/usable-by/users.rst + + Returns: + List of :obj:`~pyrogram.types.AvailableEffect`: A list of available effects is returned. + + Example: + .. code-block:: python + + # Get all available effects + await app.get_available_effects() + """ + r = await self.invoke( + raw.functions.messages.GetAvailableEffects( + hash=0 + ) + ) + + documents = {d.id: d for d in r.documents} + + return types.List( + [ + await types.AvailableEffect._parse(self, effect, documents.get(effect.effect_sticker_id, None)) + for effect in r.effects + ] + ) diff --git a/pyrogram/methods/messages/get_custom_emoji_stickers.py b/pyrogram/methods/messages/get_custom_emoji_stickers.py index 7a71f058..a819eaa2 100644 --- a/pyrogram/methods/messages/get_custom_emoji_stickers.py +++ b/pyrogram/methods/messages/get_custom_emoji_stickers.py @@ -52,4 +52,4 @@ class GetCustomEmojiStickers: sticker = await types.Sticker._parse(self, item, attributes) stickers.append(sticker) - return pyrogram.types.List(stickers) + return types.List(stickers) diff --git a/pyrogram/methods/messages/get_stickers.py b/pyrogram/methods/messages/get_stickers.py index 6f012cfd..a9e32869 100644 --- a/pyrogram/methods/messages/get_stickers.py +++ b/pyrogram/methods/messages/get_stickers.py @@ -58,7 +58,9 @@ class GetStickers: ) ) - return [ - await types.Sticker._parse(self, doc, {type(a): a for a in doc.attributes}) - for doc in sticker_set.documents - ] + return types.List( + [ + await types.Sticker._parse(self, doc, {type(a): a for a in doc.attributes}) + for doc in sticker_set.documents + ] + ) diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 1f460156..cf8fdc80 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -18,6 +18,7 @@ from .animation import Animation from .audio import Audio +from .available_effect import AvailableEffect from .boosts_status import BoostsStatus from .business_message import BusinessMessage from .checked_gift_code import CheckedGiftCode @@ -58,6 +59,7 @@ from .web_page import WebPage __all__ = [ "Animation", "Audio", + "AvailableEffect", "BoostsStatus", "BusinessMessage", "CheckedGiftCode", diff --git a/pyrogram/types/messages_and_media/available_effect.py b/pyrogram/types/messages_and_media/available_effect.py new file mode 100644 index 00000000..acf24f88 --- /dev/null +++ b/pyrogram/types/messages_and_media/available_effect.py @@ -0,0 +1,88 @@ +# 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 Optional + +from pyrogram import raw, types +from ..object import Object + + +class AvailableEffect(Object): + """Contains information about available effect. + + Parameters: + id (``int``): + Unique effect identifier. + + emoji (:py:obj:`~datetime.datetime`): + Emoji that represents the effect. + + effect_sticker_id (``int``): + sticker identifier that represents the effect. + + sticker (:obj:`~pyrogram.types.Sticker`, *optional*): + Sticker that represents the effect. + + is_premium (``bool``, *optional*): + Whether the effect is available only for premium users. + + static_icon_id (``int``, *optional*): + Static icon identifier that represents the effect. + + effect_animation_id (``int``, *optional*): + Animation identifier that represents the effect. + """ + + def __init__( + self, + *, + id: int, + emoji: str, + effect_sticker_id: int, + sticker: Optional["types.Sticker"] = None, + is_premium: Optional[bool] = None, + static_icon_id: Optional[int] = None, + effect_animation_id: Optional[int] = None + ): + super().__init__() + + self.id = id + self.emoji = emoji + self.effect_sticker_id = effect_sticker_id + self.sticker = sticker + self.is_premium = is_premium + self.static_icon_id = static_icon_id + self.effect_animation_id = effect_animation_id + + @staticmethod + async def _parse(client, effect: "raw.types.AvailableEffect", document: "raw.types.Document" = None) -> "AvailableEffect": + sticker = None + + if document: + attributes = {type(i): i for i in document.attributes} + sticker = await types.Sticker._parse(client, document, attributes) + + return AvailableEffect( + id=effect.id, + emoji=effect.emoticon, + effect_sticker_id=effect.effect_sticker_id, + sticker=sticker, + is_premium=getattr(effect, "premium_required", None), + static_icon_id=getattr(effect, "static_icon_id", None), + effect_animation_id=getattr(effect, "effect_animation_id", None) + )