From 8b52f1f71d6663602cef3c95177b70e6c3ca81eb Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 1 Jun 2024 00:43:26 +0300 Subject: [PATCH] pyrofork: Add get_available_effects method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 2 + pyrogram/methods/messages/__init__.py | 2 + .../methods/messages/get_available_effects.py | 60 +++++++++++++ pyrogram/types/messages_and_media/__init__.py | 3 +- .../messages_and_media/available_effect.py | 89 +++++++++++++++++++ 5 files changed, 155 insertions(+), 1 deletion(-) 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 1abd1a26..abfe64af 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -193,6 +193,7 @@ def pyrogram_api(): edit_inline_reply_markup send_chat_action delete_messages + get_available_effects get_messages get_media_group get_chat_history @@ -461,6 +462,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 380c8fbd..5314d93b 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -30,6 +30,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 @@ -75,6 +76,7 @@ class Messages( EditMessageMedia, EditMessageText, ForwardMessages, + GetAvailableEffects, GetMediaGroup, GetMessages, SendAudio, diff --git a/pyrogram/methods/messages/get_available_effects.py b/pyrogram/methods/messages/get_available_effects.py new file mode 100644 index 00000000..e812c568 --- /dev/null +++ b/pyrogram/methods/messages/get_available_effects.py @@ -0,0 +1,60 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# 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/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 8abad8fc..ef1a6223 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -19,6 +19,7 @@ from .animation import Animation from .audio import Audio +from .available_effect import AvailableEffect from .contact import Contact from .dice import Dice from .document import Document @@ -64,7 +65,7 @@ from .story_views import StoryViews from .exported_story_link import ExportedStoryLink __all__ = [ - "Animation", "Audio", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail", + "Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice", "Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink" ] 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..74c05c1c --- /dev/null +++ b/pyrogram/types/messages_and_media/available_effect.py @@ -0,0 +1,89 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# 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) + )