Skip to content

Commit 2a14d4e

Browse files
committed
Added view_once to send_photo, send_video, send_video_note, send_voice
1 parent 4551871 commit 2a14d4e

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

pyrogram/methods/messages/send_photo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def send_photo(
4545
partial_reply: str = None,
4646
schedule_date: datetime = None,
4747
protect_content: bool = None,
48+
view_once: bool = None,
4849
reply_markup: Union[
4950
"types.InlineKeyboardMarkup",
5051
"types.ReplyKeyboardMarkup",
@@ -89,6 +90,9 @@ async def send_photo(
8990
If you set a timer, the photo will self-destruct in *ttl_seconds*
9091
seconds after it was viewed.
9192
93+
view_once (``bool``, *optional*):
94+
Pass True if the photo should be viewable only once.
95+
9296
disable_notification (``bool``, *optional*):
9397
Sends the message silently.
9498
Users will receive a notification with no sound.
@@ -162,7 +166,7 @@ async def send_photo(
162166
file = await self.save_file(photo, progress=progress, progress_args=progress_args)
163167
media = raw.types.InputMediaUploadedPhoto(
164168
file=file,
165-
ttl_seconds=ttl_seconds,
169+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds,
166170
spoiler=has_spoiler,
167171
)
168172
elif re.match("^https?://", photo):
@@ -177,7 +181,7 @@ async def send_photo(
177181
file = await self.save_file(photo, progress=progress, progress_args=progress_args)
178182
media = raw.types.InputMediaUploadedPhoto(
179183
file=file,
180-
ttl_seconds=ttl_seconds,
184+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds,
181185
spoiler=has_spoiler
182186
)
183187

pyrogram/methods/messages/send_video.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ async def send_video(
4040
caption_entities: List["types.MessageEntity"] = None,
4141
has_spoiler: bool = None,
4242
ttl_seconds: int = None,
43+
view_once: bool = None,
4344
duration: int = 0,
4445
width: int = 0,
4546
height: int = 0,
@@ -97,6 +98,9 @@ async def send_video(
9798
If you set a timer, the video will self-destruct in *ttl_seconds*
9899
seconds after it was viewed.
99100
101+
view_once (``bool``, *optional*):
102+
Pass True if the photo should be viewable only once.
103+
100104
duration (``int``, *optional*):
101105
Duration of sent video in seconds.
102106
@@ -185,6 +189,9 @@ async def send_video(
185189
# Send self-destructing video
186190
await app.send_video("me", "video.mp4", ttl_seconds=10)
187191
192+
# Send view-once video
193+
await app.send_video("me", "video.mp4", view_once=True)
194+
188195
# Keep track of the progress while uploading
189196
async def progress(current, total):
190197
print(f"{current * 100 / total:.1f}%")
@@ -201,7 +208,7 @@ async def progress(current, total):
201208
media = raw.types.InputMediaUploadedDocument(
202209
mime_type=self.guess_mime_type(video) or "video/mp4",
203210
file=file,
204-
ttl_seconds=ttl_seconds,
211+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds,
205212
spoiler=has_spoiler,
206213
thumb=thumb,
207214
nosound_video=nosound_video,
@@ -218,18 +225,18 @@ async def progress(current, total):
218225
elif re.match("^https?://", video):
219226
media = raw.types.InputMediaDocumentExternal(
220227
url=video,
221-
ttl_seconds=ttl_seconds,
228+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds,
222229
spoiler=has_spoiler
223230
)
224231
else:
225-
media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=ttl_seconds)
232+
media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds)
226233
else:
227234
thumb = await self.save_file(thumb)
228235
file = await self.save_file(video, progress=progress, progress_args=progress_args)
229236
media = raw.types.InputMediaUploadedDocument(
230237
mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
231238
file=file,
232-
ttl_seconds=ttl_seconds,
239+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds,
233240
spoiler=has_spoiler,
234241
thumb=thumb,
235242
nosound_video=nosound_video,

pyrogram/methods/messages/send_video_note.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async def send_video_note(
4343
partial_reply: str = None,
4444
schedule_date: datetime = None,
4545
ttl_seconds: int = None,
46+
view_once: bool = None,
4647
protect_content: bool = None,
4748
reply_markup: Union[
4849
"types.InlineKeyboardMarkup",
@@ -107,6 +108,9 @@ async def send_video_note(
107108
If you set a timer, the video note will self-destruct in *ttl_seconds*
108109
seconds after it was viewed.
109110
111+
view_once (``bool``, *optional*):
112+
Pass True if the photo should be viewable only once.
113+
110114
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
111115
Additional interface options. An object for an inline keyboard, custom reply keyboard,
112116
instructions to remove reply keyboard or to force a reply from the user.
@@ -149,6 +153,9 @@ async def send_video_note(
149153
150154
# Send self-destructing video note message
151155
await app.send_video_note("me", "video_note.mp4", ttl_seconds=10)
156+
157+
# Send view-once video note message
158+
await app.send_video_note("me", "video_note.mp4", view_once=True)
152159
"""
153160
file = None
154161

@@ -169,7 +176,7 @@ async def send_video_note(
169176
h=length
170177
)
171178
],
172-
ttl_seconds=ttl_seconds
179+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds
173180
)
174181
else:
175182
media = utils.get_input_media_from_file_id(video_note, FileType.VIDEO_NOTE)
@@ -188,7 +195,7 @@ async def send_video_note(
188195
h=length
189196
)
190197
],
191-
ttl_seconds=ttl_seconds
198+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds
192199
)
193200

194201
reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id, partial_reply)

pyrogram/methods/messages/send_voice.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ async def send_voice(
4646
schedule_date: datetime = None,
4747
protect_content: bool = None,
4848
ttl_seconds: int = None,
49+
view_once: bool = None,
4950
reply_markup: Union[
5051
"types.InlineKeyboardMarkup",
5152
"types.ReplyKeyboardMarkup",
@@ -110,6 +111,9 @@ async def send_voice(
110111
If you set a timer, the voice message will self-destruct in *ttl_seconds*
111112
seconds after it was viewed.
112113
114+
view_once (``bool``, *optional*):
115+
Pass True if the photo should be viewable only once.
116+
113117
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
114118
Additional interface options. An object for an inline keyboard, custom reply keyboard,
115119
instructions to remove reply keyboard or to force a reply from the user.
@@ -171,7 +175,7 @@ async def send_voice(
171175
duration=duration
172176
)
173177
],
174-
ttl_seconds=ttl_seconds
178+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds
175179
)
176180
elif re.match("^https?://", voice):
177181
media = raw.types.InputMediaDocumentExternal(
@@ -190,7 +194,7 @@ async def send_voice(
190194
duration=duration
191195
)
192196
],
193-
ttl_seconds=ttl_seconds
197+
ttl_seconds=0x7FFFFFFF if view_once else ttl_seconds
194198
)
195199

196200
reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id, partial_reply)

0 commit comments

Comments
 (0)