Skip to content

Commit c44ea52

Browse files
committed
Add get_message_effects to get the list of available message effects
1 parent 030978d commit c44ea52

File tree

8 files changed

+197
-5
lines changed

8 files changed

+197
-5
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def get_title_list(s: str) -> list:
346346
""",
347347
stickers="""
348348
Stickers
349+
get_message_effects
349350
get_stickers
350351
""",
351352
users="""
@@ -520,6 +521,7 @@ def get_title_list(s: str) -> list:
520521
GiveawayWinners
521522
Location
522523
Message
524+
MessageEffect
523525
MessageEntity
524526
MessageImportInfo
525527
MessageOrigin

docs/source/releases/changes-in-this-fork.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
1414
| Scheme layer used: 181 |
1515
+------------------------+
1616

17-
- - Added the parameter ``message_effect_id`` to the methods :meth:`~pyrogram.Client.send_message`, :meth:`~pyrogram.Client.send_photo`, :meth:`~pyrogram.Client.send_video`, :meth:`~pyrogram.Client.send_animation`, :meth:`~pyrogram.Client.send_audio`, :meth:`~pyrogram.Client.send_document`, :meth:`~pyrogram.Client.send_sticker`, :meth:`~pyrogram.Client.send_video_note`, :meth:`~pyrogram.Client.send_voice`, :meth:`~pyrogram.Client.send_location`, :meth:`~pyrogram.Client.send_venue`, :meth:`~pyrogram.Client.send_contact`, :meth:`~pyrogram.Client.send_poll`, :meth:`~pyrogram.Client.send_dice`, :meth:`~pyrogram.Client.send_game`, and :meth:`~pyrogram.Client.send_media_group`, and the corresponding ``reply_*`` methods in the class :obj:`~pyrogram.types.Message`.
17+
- Added the :meth:`~pyrogram.Client.get_message_effects`.
18+
- Added the parameter ``message_effect_id`` to the methods :meth:`~pyrogram.Client.send_message`, :meth:`~pyrogram.Client.send_photo`, :meth:`~pyrogram.Client.send_video`, :meth:`~pyrogram.Client.send_animation`, :meth:`~pyrogram.Client.send_audio`, :meth:`~pyrogram.Client.send_document`, :meth:`~pyrogram.Client.send_sticker`, :meth:`~pyrogram.Client.send_video_note`, :meth:`~pyrogram.Client.send_voice`, :meth:`~pyrogram.Client.send_location`, :meth:`~pyrogram.Client.send_venue`, :meth:`~pyrogram.Client.send_contact`, :meth:`~pyrogram.Client.send_poll`, :meth:`~pyrogram.Client.send_dice`, :meth:`~pyrogram.Client.send_game`, and :meth:`~pyrogram.Client.send_media_group`, and the corresponding ``reply_*`` methods in the class :obj:`~pyrogram.types.Message`.
1819
- Added the field ``effect_id`` to the class :obj:`~pyrogram.types.Message`.
1920
- Added the field ``show_caption_above_media`` to the classes :obj:`~pyrogram.types.Message`, :obj:`~pyrogram.types.InputMediaAnimation`, :obj:`~pyrogram.types.InputMediaPhoto`, :obj:`~pyrogram.types.InputMediaVideo`, :obj:`~pyrogram.types.InlineQueryResultAnimation`, :obj:`~pyrogram.types.InlineQueryResultCachedAnimation`, :obj:`~pyrogram.types.InlineQueryResultPhoto`, :obj:`~pyrogram.types.InlineQueryResultCachedPhoto`, :obj:`~pyrogram.types.InlineQueryResultVideo`, :obj:`~pyrogram.types.InlineQueryResultCachedVideo`, :meth:`~pyrogram.Client.send_cached_media`, :meth:`~pyrogram.Client.send_animation`, :meth:`~pyrogram.Client.send_photo`, :meth:`~pyrogram.Client.send_video`, :meth:`~pyrogram.Client.copy_message` and :meth:`~pyrogram.Client.edit_message_caption`, and the corresponding ``reply_*`` methods.
2021
- Added support for :obj:`~pyrogram.enums.MessageEntityType.EXPANDABLE_BLOCKQUOTE` entities in received messages.

pyrogram/methods/messages/get_custom_emoji_stickers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from typing import List
2020

2121
import pyrogram
22-
from pyrogram import raw
23-
from pyrogram import types
22+
from pyrogram import raw, types
2423

2524

2625
class GetCustomEmojiStickers:
@@ -52,4 +51,4 @@ async def get_custom_emoji_stickers(
5251
sticker = await types.Sticker._parse(self, item, attributes)
5352
stickers.append(sticker)
5453

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

pyrogram/methods/stickers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from .get_message_effects import GetMessageEffects
1920
from .get_stickers import GetStickers
2021

2122

2223
class Stickers(
24+
GetMessageEffects,
2325
GetStickers,
2426
):
2527
pass
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 GetMessageEffects:
30+
async def get_message_effects(
31+
self: "pyrogram.Client"
32+
) -> List["types.MessageEffect"]:
33+
"""Returns information about all available message effects.
34+
35+
.. include:: /_includes/usable-by/users.rst
36+
37+
Returns:
38+
List of :obj:`~pyrogram.types.MessageEffect`: A list of message effects is returned.
39+
40+
Example:
41+
.. code-block:: python
42+
43+
# Get all message effects
44+
await app.get_message_effects()
45+
46+
"""
47+
r = await self.invoke(
48+
raw.functions.messages.GetAvailableEffects(
49+
hash=0
50+
)
51+
)
52+
documents = {d.id: d for d in r.documents}
53+
outlst = []
54+
for effect in r.effects:
55+
effect_animation_document = documents.get(effect.effect_sticker_id, None)
56+
static_icon_document = documents.get(effect.static_icon_id, None) if getattr(effect, "static_icon_id", None) else None
57+
select_animation_document = documents.get(effect.effect_animation_id, None) if getattr(effect, "effect_animation_id", None) else None
58+
outlst.append(
59+
await types.MessageEffect._parse(
60+
self,
61+
effect,
62+
effect_animation_document,
63+
static_icon_document,
64+
select_animation_document
65+
)
66+
)
67+
return types.List(outlst)

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from .giveaway_winners import GiveawayWinners
5656
from .gift_code import GiftCode
5757
from .gifted_premium import GiftedPremium
58+
from .message_effect import MessageEffect
5859

5960
__all__ = [
6061
"Animation",
@@ -71,6 +72,7 @@
7172
"GiveawayWinners",
7273
"Location",
7374
"Message",
75+
"MessageEffect",
7476
"MessageEntity",
7577
"MessageReactionCountUpdated",
7678
"MessageReactionUpdated",

pyrogram/types/messages_and_media/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Message(Object, Update):
147147
Options used for link preview generation for the message, if it is a text message and link preview options were changed
148148
149149
effect_id (``str``, *optional*):
150-
Unique identifier of the message effect added to the message.
150+
Unique identifier of the message effect added to the message. Use :meth:`~pyrogram.Client.get_message_effects` to get the list of available message effect ids.
151151
152152
animation (:obj:`~pyrogram.types.Animation`, *optional*):
153153
Message is an animation, information about the animation.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 MessageEffect(Object):
26+
"""Contains information about an effect added to a message.
27+
28+
Parameters:
29+
id (``int`` ``64-bit``, *optional*):
30+
Unique identifier of the effect.
31+
32+
emoji (``str``):
33+
Emoji that represents the effect.
34+
35+
static_icon (:obj:`~pyrogram.types.Sticker`, *optional*):
36+
Static icon for the effect in WEBP format; may be null if none
37+
38+
effect_animation (:obj:`~pyrogram.types.Document`, *optional*):
39+
Effect animation for the effect in TGS format.
40+
41+
select_animation (:obj:`~pyrogram.types.Document`, *optional*):
42+
Select animation for the effect in TGS format.
43+
44+
is_premium (``bool``, *optional*):
45+
True, if Telegram Premium subscription is required to use the effect.
46+
47+
"""
48+
49+
def __init__(
50+
self,
51+
*,
52+
id: int,
53+
emoji: str,
54+
static_icon: Optional["types.Sticker"] = None,
55+
effect_animation: Optional["types.Document"] = None,
56+
select_animation: Optional["types.Document"] = None,
57+
is_premium: Optional[bool] = None
58+
):
59+
super().__init__()
60+
61+
self.id = id
62+
self.emoji = emoji
63+
self.static_icon = static_icon
64+
self.effect_animation = effect_animation
65+
self.select_animation = select_animation
66+
self.is_premium = is_premium
67+
68+
@staticmethod
69+
async def _parse(
70+
client,
71+
effect: "raw.types.AvailableEffect",
72+
effect_animation_document: "raw.types.Document" = None,
73+
static_icon_document: "raw.types.Document" = None,
74+
select_animation_document: "raw.types.Document" = None
75+
) -> "MessageEffect":
76+
effect_animation = None
77+
static_icon = None
78+
select_animation = None
79+
80+
effect_sticker_id = effect.effect_sticker_id
81+
static_icon_id = getattr(effect, "static_icon_id", None)
82+
effect_animation_id = getattr(effect, "effect_animation_id", None)
83+
84+
if effect_animation_document:
85+
effect_animation = await types.Sticker._parse(
86+
client,
87+
effect_animation_document,
88+
{type(i): i for i in effect_animation_document.attributes}
89+
)
90+
# TODO: FIXME!
91+
if static_icon_document:
92+
document_attributes = {
93+
type(i): i for i in static_icon_document.attributes
94+
}
95+
file_name = getattr(document_attributes.get(raw.types.DocumentAttributeFilename, None), "file_name", None)
96+
static_icon = types.Document._parse(
97+
client,
98+
static_icon_document,
99+
file_name
100+
)
101+
if select_animation_document:
102+
document_attributes = {
103+
type(i): i for i in select_animation_document.attributes
104+
}
105+
file_name = getattr(document_attributes.get(raw.types.DocumentAttributeFilename, None), "file_name", None)
106+
select_animation = types.Document._parse(
107+
client,
108+
select_animation_document,
109+
file_name
110+
)
111+
112+
return MessageEffect(
113+
id=effect.id,
114+
emoji=effect.emoticon,
115+
static_icon=static_icon,
116+
effect_animation=effect_animation, # TODO: FIXME!
117+
select_animation=select_animation, # TODO: FIXME!
118+
is_premium=getattr(effect, "premium_required", None)
119+
)

0 commit comments

Comments
 (0)