Skip to content

Commit feff7cd

Browse files
Add get_available_effects method
1 parent d9252cd commit feff7cd

File tree

7 files changed

+160
-5
lines changed

7 files changed

+160
-5
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def get_title_list(s: str) -> list:
175175
edit_inline_reply_markup
176176
send_chat_action
177177
delete_messages
178+
get_available_effects
178179
get_messages
179180
get_scheduled_messages
180181
get_stickers
@@ -476,6 +477,7 @@ def get_title_list(s: str) -> list:
476477
Photo
477478
Thumbnail
478479
Audio
480+
AvailableEffect
479481
Document
480482
Animation
481483
Video

pyrogram/methods/messages/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .edit_message_reply_markup import EditMessageReplyMarkup
3030
from .edit_message_text import EditMessageText
3131
from .forward_messages import ForwardMessages
32+
from .get_available_effects import GetAvailableEffects
3233
from .get_chat_history import GetChatHistory
3334
from .get_chat_history_count import GetChatHistoryCount
3435
from .get_custom_emoji_stickers import GetCustomEmojiStickers
@@ -80,6 +81,7 @@ class Messages(
8081
EditMessageMedia,
8182
EditMessageText,
8283
ForwardMessages,
84+
GetAvailableEffects,
8385
GetMediaGroup,
8486
GetMessages,
8587
GetScheduledMessages,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import logging
20+
from typing import List
21+
22+
import pyrogram
23+
from pyrogram import raw
24+
from pyrogram import types
25+
26+
log = logging.getLogger(__name__)
27+
28+
29+
class GetAvailableEffects:
30+
async def get_available_effects(
31+
self: "pyrogram.Client"
32+
) -> List["types.AvailableEffect"]:
33+
"""Get all available effects.
34+
35+
.. include:: /_includes/usable-by/users.rst
36+
37+
Returns:
38+
List of :obj:`~pyrogram.types.AvailableEffect`: A list of available effects is returned.
39+
40+
Example:
41+
.. code-block:: python
42+
43+
# Get all available effects
44+
await app.get_available_effects()
45+
"""
46+
r = await self.invoke(
47+
raw.functions.messages.GetAvailableEffects(
48+
hash=0
49+
)
50+
)
51+
52+
documents = {d.id: d for d in r.documents}
53+
54+
return types.List(
55+
[
56+
await types.AvailableEffect._parse(self, effect, documents.get(effect.effect_sticker_id, None))
57+
for effect in r.effects
58+
]
59+
)

pyrogram/methods/messages/get_custom_emoji_stickers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ async def get_custom_emoji_stickers(
5252
sticker = await types.Sticker._parse(self, item, attributes)
5353
stickers.append(sticker)
5454

55-
return pyrogram.types.List(stickers)
55+
return types.List(stickers)

pyrogram/methods/messages/get_stickers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ async def get_stickers(
5858
)
5959
)
6060

61-
return [
62-
await types.Sticker._parse(self, doc, {type(a): a for a in doc.attributes})
63-
for doc in sticker_set.documents
64-
]
61+
return types.List(
62+
[
63+
await types.Sticker._parse(self, doc, {type(a): a for a in doc.attributes})
64+
for doc in sticker_set.documents
65+
]
66+
)

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from .animation import Animation
2020
from .audio import Audio
21+
from .available_effect import AvailableEffect
2122
from .boosts_status import BoostsStatus
2223
from .business_message import BusinessMessage
2324
from .checked_gift_code import CheckedGiftCode
@@ -58,6 +59,7 @@
5859
__all__ = [
5960
"Animation",
6061
"Audio",
62+
"AvailableEffect",
6163
"BoostsStatus",
6264
"BusinessMessage",
6365
"CheckedGiftCode",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Optional
20+
21+
from pyrogram import raw, types
22+
from ..object import Object
23+
24+
25+
class AvailableEffect(Object):
26+
"""Contains information about available effect.
27+
28+
Parameters:
29+
id (``int``):
30+
Unique effect identifier.
31+
32+
emoji (:py:obj:`~datetime.datetime`):
33+
Emoji that represents the effect.
34+
35+
effect_sticker_id (``int``):
36+
sticker identifier that represents the effect.
37+
38+
sticker (:obj:`~pyrogram.types.Sticker`, *optional*):
39+
Sticker that represents the effect.
40+
41+
is_premium (``bool``, *optional*):
42+
Whether the effect is available only for premium users.
43+
44+
static_icon_id (``int``, *optional*):
45+
Static icon identifier that represents the effect.
46+
47+
effect_animation_id (``int``, *optional*):
48+
Animation identifier that represents the effect.
49+
"""
50+
51+
def __init__(
52+
self,
53+
*,
54+
id: int,
55+
emoji: str,
56+
effect_sticker_id: int,
57+
sticker: Optional["types.Sticker"] = None,
58+
is_premium: Optional[bool] = None,
59+
static_icon_id: Optional[int] = None,
60+
effect_animation_id: Optional[int] = None
61+
):
62+
super().__init__()
63+
64+
self.id = id
65+
self.emoji = emoji
66+
self.effect_sticker_id = effect_sticker_id
67+
self.sticker = sticker
68+
self.is_premium = is_premium
69+
self.static_icon_id = static_icon_id
70+
self.effect_animation_id = effect_animation_id
71+
72+
@staticmethod
73+
async def _parse(client, effect: "raw.types.AvailableEffect", document: "raw.types.Document" = None) -> "AvailableEffect":
74+
sticker = None
75+
76+
if document:
77+
attributes = {type(i): i for i in document.attributes}
78+
sticker = await types.Sticker._parse(client, document, attributes)
79+
80+
return AvailableEffect(
81+
id=effect.id,
82+
emoji=effect.emoticon,
83+
effect_sticker_id=effect.effect_sticker_id,
84+
sticker=sticker,
85+
is_premium=getattr(effect, "premium_required", None),
86+
static_icon_id=getattr(effect, "static_icon_id", None),
87+
effect_animation_id=getattr(effect, "effect_animation_id", None)
88+
)

0 commit comments

Comments
 (0)