Add get_available_effects method

This commit is contained in:
KurimuzonAkuma 2024-06-01 00:43:26 +03:00
parent d9252cd187
commit feff7cd29d
7 changed files with 160 additions and 5 deletions

View File

@ -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

View File

@ -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,

View File

@ -0,0 +1,59 @@
# 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 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
]
)

View File

@ -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)

View File

@ -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
]
)

View File

@ -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",

View File

@ -0,0 +1,88 @@
# 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/>.
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)
)