Skip to content

Commit 5aae094

Browse files
feat: Add media to Poll and PollOption class
1 parent 5e60e7a commit 5aae094

13 files changed

Lines changed: 377 additions & 51 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def get_title_list(s: str) -> list:
738738
ManagedBotCreated
739739
MaskPosition
740740
MediaArea
741+
MessageContent
741742
Venue
742743
Sticker
743744
Game

pyrogram/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def inline_query_parser(update, users, chats):
172172

173173
async def poll_parser(update, users, chats):
174174
return (
175-
pyrogram.types.Poll._parse_update(self.client, update, users, chats),
175+
await pyrogram.types.Poll._parse_update(self.client, update, users, chats),
176176
PollHandler
177177
)
178178

pyrogram/methods/messages/retract_vote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ async def retract_vote(
6161
users = {i.id: i for i in r.users}
6262
chats = {i.id: i for i in r.chats}
6363

64-
return types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)
64+
return await types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)

pyrogram/methods/messages/send_poll.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def send_poll(
3131
chat_id: Union[int, str],
3232
question: Union[str, "types.FormattedText"],
3333
options: List[Union[str, "types.InputPollOption"]],
34-
media: Optional["types.InputMedia"] = None,
34+
description_media: Optional["types.InputMedia"] = None,
3535
message_thread_id: Optional[int] = None,
3636
business_connection_id: Optional[str] = None,
3737
is_anonymous: bool = True,
@@ -43,6 +43,7 @@ async def send_poll(
4343
hide_results_until_closes: Optional[bool] = None,
4444
correct_option_ids: Optional[List[int]] = None,
4545
explanation: Optional[Union[str, "types.FormattedText"]] = None,
46+
explanation_media: Optional["types.InputMedia"] = None,
4647
open_period: Optional[int] = None,
4748
close_date: Optional[datetime] = None,
4849
is_closed: Optional[bool] = None,
@@ -86,9 +87,8 @@ async def send_poll(
8687
options (List of :obj:`~pyrogram.types.InputPollOption`):
8788
List of 2-12 answer options.
8889
89-
media (:obj:`~pyrogram.types.InputMediaPhoto` | :obj:`~pyrogram.types.InputMediaVideo` | :obj:`~pyrogram.types.InputMediaSticker` | :obj:`~pyrogram.types.Location`, *optional*):
90+
explanation_media (:obj:`~pyrogram.types.InputMedia` | :obj:`~pyrogram.types.Location`, *optional*):
9091
Media attached to the poll.
91-
Currently supports only photo, video, sticker or location.
9292
9393
message_thread_id (``int``, *optional*):
9494
Unique identifier for the target message thread (topic) of the forum.
@@ -128,6 +128,9 @@ async def send_poll(
128128
explanation (``str`` | :obj:`~pyrogram.types.FormattedText`, *optional*):
129129
Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing.
130130
131+
explanation_media (:obj:`~pyrogram.types.InputMedia` | :obj:`~pyrogram.types.Location`, *optional*):
132+
Media attached to the explanation.
133+
131134
open_period (``int``, *optional*):
132135
Amount of time in seconds the poll will be active after creation, 5-2628000.
133136
Can't be used together with *close_date*.
@@ -199,7 +202,7 @@ async def send_poll(
199202
await app.send_poll(
200203
chat_id=chat_id,
201204
question="Where we are?",
202-
media=types.InputMediaPhoto("photo.jpg"),
205+
description_media=types.InputMediaPhoto("photo.jpg"),
203206
options=[
204207
types.InputPollOption(
205208
text="Maybe here?",
@@ -208,24 +211,13 @@ async def send_poll(
208211
types.InputPollOption(
209212
text="Or here?",
210213
media=types.Location(
211-
longitude=49.807760,
212-
latitude=73.088504
214+
latitude=49.807760,
215+
longitude=73.088504
213216
),
214217
),
215218
]
216219
)
217220
"""
218-
if media is not None and not isinstance(
219-
media,
220-
(
221-
types.InputMediaPhoto,
222-
types.InputMediaVideo,
223-
types.InputMediaSticker,
224-
types.Location,
225-
),
226-
):
227-
raise ValueError("Unsupported media type")
228-
229221
if isinstance(question, str):
230222
question = types.FormattedText(text=question)
231223

@@ -283,9 +275,10 @@ async def send_poll(
283275
close_date=utils.datetime_to_timestamp(close_date)
284276
),
285277
correct_answers=correct_option_ids,
286-
attached_media=await media.write(client=self) if media is not None else None,
278+
attached_media=await description_media.write(client=self) if description_media is not None else None,
287279
solution=solution,
288-
solution_entities=solution_entities
280+
solution_entities=solution_entities,
281+
solution_media=await explanation_media.write(client=self) if explanation_media is not None else None
289282
),
290283
message=message or "",
291284
entities=entities or None,

pyrogram/methods/messages/stop_poll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ async def stop_poll(
7878
users = {i.id: i for i in r.users}
7979
chats = {i.id: i for i in r.chats}
8080

81-
return types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)
81+
return await types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)

pyrogram/methods/messages/vote_poll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ async def vote_poll(
6868
users = {i.id: i for i in r.users}
6969
chats = {i.id: i for i in r.chats}
7070

71-
return types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)
71+
return await types.Poll._parse(self, r.updates[0], None, users=users, chats=chats)

pyrogram/types/input_content/input_poll_option.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class InputPollOption(Object):
3131
text (``str`` | :obj:`~pyrogram.enums.FormattedText`, *optional*):
3232
Option text, 1-100 characters.
3333
34-
media (:obj:`~pyrogram.types.InputMediaPhoto` | :obj:`~pyrogram.types.InputMediaVideo` | :obj:`~pyrogram.types.InputMediaSticker` | :obj:`~pyrogram.types.Location`, *optional*):
35-
Media associated with the option.
36-
Currently supports only photo, video, sticker or location.
34+
media (:obj:`~pyrogram.types.InputMedia` | :obj:`~pyrogram.types.Location`, *optional*):
35+
Option media.
36+
Currently, can be only of the types Animation, Location, Photo, Sticker, Venue, or Video without caption.
3737
"""
3838

3939
def __init__(
@@ -42,9 +42,7 @@ def __init__(
4242
text: Union[str, "types.FormattedText"],
4343
media: Optional[
4444
Union[
45-
"types.InputMediaPhoto",
46-
"types.InputMediaVideo",
47-
"types.InputMediaSticker",
45+
"types.InputMedia",
4846
"types.Location",
4947
]
5048
] = None,
@@ -58,17 +56,6 @@ async def write(self, client: "pyrogram.Client") -> "raw.types.InputPollAnswer":
5856
if isinstance(self.text, str):
5957
self.text = types.FormattedText(text=self.text)
6058

61-
if self.media is not None and not isinstance(
62-
self.media,
63-
(
64-
types.InputMediaPhoto,
65-
types.InputMediaVideo,
66-
types.InputMediaSticker,
67-
types.Location,
68-
),
69-
):
70-
raise ValueError(f"Unsupported media type: {type(self.media)}")
71-
7259
return raw.types.InputPollAnswer(
7360
text=await self.text.write(client),
7461
media=await self.media.write(client=client) if self.media is not None else None,

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from .managed_bot_created import ManagedBotCreated
7575
from .mask_position import MaskPosition
7676
from .media_area import MediaArea
77+
from .message_content import MessageContent
7778
from .message import Message
7879
from .message_entity import MessageEntity
7980
from .message_origin import MessageOrigin
@@ -208,6 +209,7 @@
208209
"ManagedBotCreated",
209210
"MaskPosition",
210211
"MediaArea",
212+
"MessageContent",
211213
"Message",
212214
"MessageEntity",
213215
"MessageOrigin",

pyrogram/types/messages_and_media/external_reply_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ async def _parse(
282282
document = types.Document._parse(client, doc, file_name)
283283
media_type = enums.MessageMediaType.DOCUMENT
284284
elif isinstance(media, raw.types.MessageMediaPoll):
285-
poll = types.Poll._parse(client, media, None, users=users, chats=chats)
285+
poll = await types.Poll._parse(client, media, None, users=users, chats=chats)
286286
media_type = enums.MessageMediaType.POLL
287287
elif isinstance(media, raw.types.MessageMediaDice):
288288
dice = types.Dice._parse(client, media)

pyrogram/types/messages_and_media/message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ class Message(Object, Update):
590590
IETF language tag of the message language on which it can be summarized.
591591
None if summary isn't available for the message.
592592
"""
593+
# TODO: replace media params to MessageContent class
593594
def __init__(
594595
self,
595596
*,
@@ -1572,7 +1573,7 @@ async def _parse_message(
15721573
media_type = enums.MessageMediaType.WEB_PAGE
15731574
web_page = types.WebPage._parse(client, media)
15741575
elif isinstance(media, raw.types.MessageMediaPoll):
1575-
poll = types.Poll._parse(
1576+
poll = await types.Poll._parse(
15761577
client,
15771578
media,
15781579
description=types.FormattedText._parse(

0 commit comments

Comments
 (0)