Skip to content

Commit 7675b40

Browse files
authored
Update names similar to Bot API 8.3 names
1 parent 111cbe1 commit 7675b40

File tree

9 files changed

+117
-38
lines changed

9 files changed

+117
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Changes in this Fork
3636
- Added ``message.content`` property.
3737
- Added the parameter ``pinned`` and made the parameter ``chat_id`` optional in :meth:`~pyrogram.Client.get_messages`. **NOTE**: Please be aware about using the correct :doc:`Message Identifiers <../../topics/message-identifiers>`, when using this method.
3838
- Added the ``cover`` and ``start_timestamp`` parameters in :meth:`~pyrogram.Client.send_video` and :obj:`~pyrogram.types.InputPaidMediaVideo`.
39-
- Added the ``new_video_start_timestamp`` and renamed the ``send_copy`` and ``remove_caption`` parameters in :meth:`~pyrogram.Client.forward_messages` and :meth:`~pyrogram.types.Message.forward`.
39+
- Added the ``video_start_timestamp`` and renamed the ``send_copy`` and ``remove_caption`` parameters in :meth:`~pyrogram.Client.forward_messages` and :meth:`~pyrogram.types.Message.forward`.
4040
- Added the ``gift_count`` to the :obj:`~pyrogram.types.Chat`.
4141
- Added the :meth:`~pyrogram.Client.get_similar_bots`.
4242
- Changed types in :obj:`~pyrogram.types.UpgradedGift`, :obj:`~pyrogram.types.UserGift`.

pyrogram/methods/business/get_available_gifts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def get_available_gifts(
3131
.. include:: /_includes/usable-by/users-bots.rst
3232
3333
Returns:
34-
List of :obj:`~pyrogram.types.Gift` | :obj:`~pyrogram.types.UpgradedGift`: On success, a list of star gifts is returned.
34+
List of :obj:`~pyrogram.types.Gift` | :obj:`~pyrogram.types.UpgradedGift`: On success, a list of star gifts that can be sent by the Client to users and channel chats is returned.
3535
3636
Example:
3737
.. code-block:: python

pyrogram/methods/business/send_gift.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,32 @@
2626
class SendGift:
2727
async def send_gift(
2828
self: "pyrogram.Client",
29-
user_id: Union[int, str],
30-
gift_id: int,
29+
*,
30+
user_id: Union[int, str] = None,
31+
chat_id: Union[int, str] = None,
32+
gift_id: int = None,
3133
pay_for_upgrade: Optional[bool] = None,
3234
text: Optional[str] = None,
33-
parse_mode: Optional["enums.ParseMode"] = None,
34-
entities: Optional[list["types.MessageEntity"]] = None,
35+
text_parse_mode: Optional["enums.ParseMode"] = None,
36+
text_entities: Optional[list["types.MessageEntity"]] = None,
3537
is_private: Optional[bool] = None,
3638
) -> bool:
37-
"""Sends a gift to another user.
39+
"""Sends a gift to the given user or channel chat. The gift can't be converted to Telegram Stars by the receiver.
3840
3941
.. include:: /_includes/usable-by/users-bots.rst
4042
43+
You must use exactly one of ``user_id`` OR ``chat_id``.
44+
4145
Parameters:
4246
user_id (``int`` | ``str``):
43-
Unique identifier (int) or username (str) of the user that will receive the gift.
47+
Required if ``chat_id`` is not specified.
48+
Unique identifier (int) or username (str) of the target user that will receive the gift.
49+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
50+
For a contact that exists in your Telegram address book you can use his phone number (str).
51+
52+
chat_id (``int`` | ``str``):
53+
Required if ``user_id`` is not specified.
54+
Unique identifier (int) or username (str) for the chat or username of the channel that will receive the gift.
4455
For your personal cloud (Saved Messages) you can simply use "me" or "self".
4556
For a contact that exists in your Telegram address book you can use his phone number (str).
4657
@@ -53,12 +64,12 @@ async def send_gift(
5364
text (``str``, *optional*):
5465
Text that will be shown along with the gift. 0-``gift_text_length_max`` characters.
5566
56-
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
67+
text_parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
5768
By default, texts are parsed using both Markdown and HTML styles.
5869
You can combine both syntaxes together.
5970
60-
entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
61-
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
71+
text_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
72+
List of special entities that appear in message text, which can be specified instead of *text_parse_mode*.
6273
Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are allowed.
6374
6475
is_private (``bool``, *optional*):
@@ -77,12 +88,15 @@ async def send_gift(
7788
app.send_gift(user_id=user_id, gift_id=123)
7889
7990
"""
80-
peer = await self.resolve_peer(user_id)
81-
82-
if not isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
83-
raise ValueError("user_id must belong to a user.")
84-
85-
text, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()
91+
peer = None
92+
if user_id:
93+
peer = await self.resolve_peer(user_id)
94+
elif chat_id:
95+
peer = await self.resolve_peer(chat_id)
96+
# TODO
97+
if not peer:
98+
raise ValueError("You must use exactly one of user_id OR chat_id")
99+
text, entities = (await utils.parse_text_entities(self, text, text_parse_mode, text_entities)).values()
86100

87101
invoice = raw.types.InputInvoiceStarGift(
88102
user_id=peer,

pyrogram/methods/messages/forward_messages.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def forward_messages(
3636
allow_paid_broadcast: bool = None,
3737
send_copy: bool = None,
3838
remove_caption: bool = None,
39-
new_video_start_timestamp: int = None,
39+
video_start_timestamp: int = None,
4040
send_as: Union[int, str] = None,
4141
schedule_date: datetime = None
4242
) -> Union["types.Message", list["types.Message"]]:
@@ -77,8 +77,8 @@ async def forward_messages(
7777
remove_caption (``bool``, *optional*):
7878
Pass True to remove media captions of message copies.
7979
80-
new_video_start_timestamp (``int``, *optional*):
81-
The new video start timestamp. Pass time to replace video start timestamp in the forwarded message.
80+
video_start_timestamp (``int``, *optional*):
81+
New start timestamp for the forwarded video in the message.
8282
8383
send_as (``int`` | ``str``):
8484
Unique identifier (int) or username (str) of the chat or channel to send the message as.
@@ -114,7 +114,7 @@ async def forward_messages(
114114
id=message_ids,
115115
silent=disable_notification or None,
116116
# TODO
117-
video_timestamp=new_video_start_timestamp,
117+
video_timestamp=video_start_timestamp,
118118
drop_author=send_copy,
119119
drop_media_captions=remove_caption,
120120
noforwards=protect_content,

pyrogram/methods/messages/send_video.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ async def send_video(
4545
width: int = 0,
4646
height: int = 0,
4747
thumb: Union[str, "io.BytesIO"] = None,
48+
cover: Optional[Union[str, "io.BytesIO"]] = None,
49+
start_timestamp: int = None,
4850
has_spoiler: bool = None,
4951
supports_streaming: bool = True,
5052
disable_notification: bool = None,
@@ -65,8 +67,6 @@ async def send_video(
6567
view_once: bool = None,
6668
file_name: str = None,
6769
mime_type: str = None,
68-
cover: Optional[Union[str, "io.BytesIO"]] = None,
69-
start_timestamp: int = None,
7070
schedule_date: datetime = None,
7171
reply_to_message_id: int = None,
7272
progress: Callable = None,
@@ -121,6 +121,12 @@ async def send_video(
121121
A thumbnail's width and height should not exceed 320 pixels.
122122
Thumbnails can't be reused and can be only uploaded as a new file.
123123
124+
cover (``str`` | :obj:`io.BytesIO`, *optional*):
125+
Cover for the video in the message. Pass None to skip cover uploading.
126+
127+
start_timestamp (``int``, *optional*):
128+
Timestamp from which the video playing must start, in seconds.
129+
124130
has_spoiler (``bool``, *optional*):
125131
Pass True if the video needs to be covered with a spoiler animation.
126132
@@ -175,12 +181,6 @@ async def send_video(
175181
mime_type (``str``, *optional*):
176182
no docs!
177183
178-
cover (``str`` | :obj:`io.BytesIO`, *optional*):
179-
Cover of the video; pass None to skip cover uploading.
180-
181-
start_timestamp (``int``, *optional*):
182-
Timestamp from which the video playing must start, in seconds.
183-
184184
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
185185
Date when the message will be automatically sent.
186186
@@ -248,6 +248,47 @@ async def progress(current, total):
248248
file = None
249249
ttl_seconds = 0x7FFFFFFF if view_once else ttl_seconds
250250

251+
coverfile = None
252+
if cover:
253+
is_bytes_io = isinstance(cover, io.BytesIO)
254+
is_uploaded_file = is_bytes_io or os.path.isfile(cover)
255+
is_external_url = not is_uploaded_file and re.match("^https?://", cover)
256+
257+
if is_bytes_io and not hasattr(cover, "name"):
258+
cover.name = "cover.jpg"
259+
if is_uploaded_file:
260+
coverfile = await self.invoke(
261+
raw.functions.messages.UploadMedia(
262+
business_connection_id=business_connection_id,
263+
peer=await self.resolve_peer(chat_id),
264+
media=raw.types.InputMediaUploadedPhoto(
265+
file=await self.save_file(cover)
266+
)
267+
)
268+
)
269+
coverfile = raw.types.InputPhoto(
270+
id=coverfile.photo.id,
271+
access_hash=coverfile.photo.access_hash,
272+
file_reference=coverfile.photo.file_reference
273+
)
274+
elif is_external_url:
275+
coverfile = await self.invoke(
276+
raw.functions.messages.UploadMedia(
277+
business_connection_id=business_connection_id,
278+
peer=await self.resolve_peer(chat_id),
279+
media=raw.types.InputMediaPhotoExternal(
280+
url=cover
281+
)
282+
)
283+
)
284+
coverfile = raw.types.InputPhoto(
285+
id=coverfile.photo.id,
286+
access_hash=coverfile.photo.access_hash,
287+
file_reference=coverfile.photo.file_reference
288+
)
289+
else:
290+
coverfile = (utils.get_input_media_from_file_id(cover, FileType.PHOTO)).id
291+
251292
try:
252293
if isinstance(video, str):
253294
if os.path.isfile(video):
@@ -269,15 +310,15 @@ async def progress(current, total):
269310
),
270311
raw.types.DocumentAttributeFilename(file_name=file_name or os.path.basename(video))
271312
],
272-
video_cover=await self.save_file(cover) if cover else None,
313+
video_cover=coverfile,
273314
video_timestamp=start_timestamp
274315
)
275316
elif re.match("^https?://", video):
276317
media = raw.types.InputMediaDocumentExternal(
277318
url=video,
278319
ttl_seconds=ttl_seconds,
279320
spoiler=has_spoiler,
280-
video_cover=await self.save_file(cover) if cover else None,
321+
video_cover=coverfile,
281322
video_timestamp=start_timestamp
282323
)
283324
else:
@@ -287,6 +328,9 @@ async def progress(current, total):
287328
ttl_seconds=ttl_seconds,
288329
has_spoiler=has_spoiler
289330
)
331+
media.video_cover = coverfile
332+
media.video_timestamp = start_timestamp
333+
290334
else:
291335
file = await self.save_file(video, progress=progress, progress_args=progress_args)
292336
thumb = await self.save_file(thumb)
@@ -305,7 +349,7 @@ async def progress(current, total):
305349
),
306350
raw.types.DocumentAttributeFilename(file_name=file_name or video.name)
307351
],
308-
video_cover=await self.save_file(cover) if cover else None,
352+
video_cover=coverfile,
309353
video_timestamp=start_timestamp
310354
)
311355

pyrogram/methods/messages/set_reaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def set_reaction(
3636
add_to_recent: bool = True
3737
) -> "types.MessageReactions":
3838
"""Use this method to change the chosen reactions on a message.
39-
Bots can't react to service messages.
39+
Service messages of some types can't be reacted to. Use :obj:`~pyrogram.types.Message._raw.reactions_are_possible` to check if it is possible to react to the message.
4040
Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
4141
Bots can't use paid reactions.
4242

pyrogram/types/input_media/input_media_video.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class InputMediaVideo(InputMedia):
7878
disable_content_type_detection (``bool``, *optional*):
7979
Pass True, if the uploaded video is a video message with no sound.
8080
Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always True, if the document is sent as part of an album.
81+
82+
cover (``str`` | :obj:`io.BytesIO`, *optional*):
83+
Cover for the video in the message. pass None to skip cover uploading.
84+
85+
start_timestamp (``int``, *optional*):
86+
Timestamp from which the video playing must start, in seconds.
87+
8188
"""
8289

8390
def __init__(
@@ -95,6 +102,8 @@ def __init__(
95102
supports_streaming: bool = True,
96103
has_spoiler: bool = None,
97104
disable_content_type_detection: bool = None,
105+
cover: Optional[Union[str, "io.BytesIO"]] = None,
106+
start_timestamp: int = None
98107
):
99108
super().__init__(media, caption, parse_mode, caption_entities)
100109

@@ -107,3 +116,5 @@ def __init__(
107116
self.supports_streaming = supports_streaming
108117
self.has_spoiler = has_spoiler
109118
self.disable_content_type_detection = disable_content_type_detection
119+
self.cover = cover
120+
self.start_timestamp = start_timestamp

pyrogram/types/input_paid_media/input_paid_media_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class InputPaidMediaVideo(InputPaidMedia):
5555
Pass True, if the uploaded video is suitable for streaming.
5656
5757
cover (``str`` | :obj:`io.BytesIO`, *optional*):
58-
Cover of the video; pass None to skip cover uploading.
58+
Cover for the video in the message. pass None to skip cover uploading.
5959
6060
start_timestamp (``int``, *optional*):
6161
Timestamp from which the video playing must start, in seconds.

pyrogram/types/messages_and_media/message.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,8 @@ async def reply_video(
35513551
width: int = 0,
35523552
height: int = 0,
35533553
thumb: Union[str, "io.BytesIO"] = None,
3554+
cover: Optional[Union[str, "io.BytesIO"]] = None,
3555+
start_timestamp: int = None,
35543556
has_spoiler: bool = None,
35553557
supports_streaming: bool = True,
35563558
disable_notification: bool = None,
@@ -3630,6 +3632,12 @@ async def reply_video(
36303632
A thumbnail's width and height should not exceed 320 pixels.
36313633
Thumbnails can't be reused and can be only uploaded as a new file.
36323634
3635+
cover (``str`` | :obj:`io.BytesIO`, *optional*):
3636+
Cover for the video in the message. Pass None to skip cover uploading.
3637+
3638+
start_timestamp (``int``, *optional*):
3639+
Timestamp from which the video playing must start, in seconds.
3640+
36333641
has_spoiler (``bool``, *optional*):
36343642
Pass True if the video needs to be covered with a spoiler animation.
36353643
@@ -3730,6 +3738,8 @@ async def reply_video(
37303738
width=width,
37313739
height=height,
37323740
thumb=thumb,
3741+
cover=cover,
3742+
start_timestamp=start_timestamp,
37333743
has_spoiler=has_spoiler,
37343744
supports_streaming=supports_streaming,
37353745
disable_notification=disable_notification,
@@ -4582,7 +4592,7 @@ async def forward(
45824592
allow_paid_broadcast: bool = None,
45834593
send_copy: bool = None,
45844594
remove_caption: bool = None,
4585-
new_video_start_timestamp: int = None,
4595+
video_start_timestamp: int = None,
45864596
send_as: Union[int, str] = None,
45874597
schedule_date: datetime = None
45884598
) -> Union["types.Message", list["types.Message"]]:
@@ -4628,8 +4638,8 @@ async def forward(
46284638
remove_caption (``bool``, *optional*):
46294639
Pass True to remove media captions of message copies.
46304640
4631-
new_video_start_timestamp (``int``, *optional*):
4632-
The new video start timestamp. Pass time to replace video start timestamp in the forwarded message.
4641+
video_start_timestamp (``int``, *optional*):
4642+
New start timestamp for the copied video in the message.
46334643
46344644
send_as (``int`` | ``str``):
46354645
Unique identifier (int) or username (str) of the chat or channel to send the message as.
@@ -4657,7 +4667,7 @@ async def forward(
46574667
allow_paid_broadcast=allow_paid_broadcast,
46584668
send_copy=send_copy,
46594669
remove_caption=remove_caption,
4660-
new_video_start_timestamp=new_video_start_timestamp,
4670+
video_start_timestamp=video_start_timestamp,
46614671
send_as=send_as,
46624672
schedule_date=schedule_date
46634673
)

0 commit comments

Comments
 (0)