1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
1919import os
20- from typing import List , Union , BinaryIO , Callable
20+ from typing import Union , BinaryIO , Callable
2121
2222import pyrogram
23- from pyrogram import enums , raw , types , utils , StopTransmission
23+ from pyrogram import raw , types , utils , StopTransmission
2424from pyrogram .errors import FilePartMissing
2525
26- class EditStory :
27- async def edit_story (
26+ class EditStoryMedia :
27+ async def edit_story_media (
2828 self : "pyrogram.Client" ,
2929 chat_id : Union [int , str ],
3030 story_id : int ,
3131 media : Union [str , BinaryIO ] = None ,
32- caption : str = None ,
3332 duration : int = 0 ,
3433 width : int = 0 ,
3534 height : int = 0 ,
3635 thumb : Union [str , BinaryIO ] = None ,
3736 supports_streaming : bool = True ,
3837 file_name : str = None ,
39- privacy : "enums.StoriesPrivacyRules" = None ,
40- allowed_users : List [Union [int , str ]] = None ,
41- disallowed_users : List [Union [int , str ]] = None ,
42- parse_mode : "enums.ParseMode" = None ,
43- caption_entities : List ["types.MessageEntity" ] = None ,
4438 progress : Callable = None ,
4539 progress_args : tuple = ()
4640 ) -> "types.Story" :
47- """Edit story.
41+ """Edit story media .
4842
4943 .. include:: /_includes/usable-by/users.rst
5044
5145 Parameters:
5246 chat_id (``int`` | ``str``):
5347 Unique identifier (int) or username (str) of the target chat.
5448 For your personal cloud (Saved Messages) you can simply use "me" or "self".
55- For a contact that exists in your Telegram address book you can use his phone number (str).
49+
50+ story_id (``int``):
51+ Story identifier in the chat specified in chat_id.
5652
5753 media (``str`` | ``BinaryIO``, *optional*):
5854 Video or photo to send.
5955 Pass a file_id as string to send a animation that exists on the Telegram servers,
6056 pass a file path as string to upload a new animation that exists on your local machine, or
6157 pass a binary file-like object with its attribute ".name" set for in-memory uploads.
6258
63- caption (``str``, *optional*):
64- Story caption, 0-1024 characters.
65-
6659 duration (``int``, *optional*):
6760 Duration of sent video in seconds.
6861
@@ -78,27 +71,6 @@ async def edit_story(
7871 A thumbnail's width and height should not exceed 320 pixels.
7972 Thumbnails can't be reused and can be only uploaded as a new file.
8073
81- privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
82- Story privacy.
83-
84- allowed_users (List of ``int``, *optional*):
85- List of user_id or chat_id of chat users who are allowed to view stories.
86- Note: chat_id available only with :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS`.
87- Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.CLOSE_FRIENDS`
88- and :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS` only
89-
90- disallowed_users (List of ``int``, *optional*):
91- List of user_id whos disallow to view the stories.
92- Note: Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
93- and :obj:`~pyrogram.enums.StoriesPrivacyRules.CONTACTS` only
94-
95- parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
96- By default, texts are parsed using both Markdown and HTML styles.
97- You can combine both syntaxes together.
98-
99- caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
100- List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
101-
10274 progress (``Callable``, *optional*):
10375 Pass a callback function to view the file transmission progress.
10476 The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
@@ -111,58 +83,19 @@ async def edit_story(
11183 object or a Client instance in order to edit the message with the updated progress status.
11284
11385 Returns:
114- :obj:`~pyrogram.types.Story` a single story is returned.
86+ :obj:`~pyrogram.types.Story`: On success, the edited story is returned.
11587
11688 Example:
11789 .. code-block:: python
11890
119- # Edit story in your profile
120- await app.edit_story("me", "story.png", caption='My new story!' )
91+ # Replace the current media with a local photo
92+ await app.edit_story_media(chat_id, story_id, "new_photo.jpg" )
12193
122- # Edit story in channel
123- await app.edit_story(123456, "story.png", caption='My new story!')
124-
125- Raises:
126- ValueError: In case of invalid arguments.
94+ # Replace the current media with a local video
95+ await app.edit_story_media(chat_id, story_id, "new_video.mp4")
12796 """
12897 # TODO: media_areas
12998
130- message , entities = (await utils .parse_text_entities (self , caption , parse_mode , caption_entities )).values ()
131-
132- privacy_rules = []
133-
134- if privacy :
135- if privacy == enums .StoriesPrivacyRules .PUBLIC :
136- privacy_rules .append (raw .types .InputPrivacyValueAllowAll ())
137- if disallowed_users :
138- users = [await self .resolve_peer (user_id ) for user_id in disallowed_users ]
139- privacy_rules .append (raw .types .InputPrivacyValueDisallowUsers (users = users ))
140- elif privacy == enums .StoriesPrivacyRules .CONTACTS :
141- privacy_rules = [raw .types .InputPrivacyValueAllowContacts ()]
142- if disallowed_users :
143- users = [await self .resolve_peer (user_id ) for user_id in disallowed_users ]
144- privacy_rules .append (raw .types .InputPrivacyValueDisallowUsers (users = users ))
145- elif privacy == enums .StoriesPrivacyRules .CLOSE_FRIENDS :
146- privacy_rules = [raw .types .InputPrivacyValueAllowCloseFriends ()]
147- if allowed_users :
148- users = [await self .resolve_peer (user_id ) for user_id in allowed_users ]
149- privacy_rules .append (raw .types .InputPrivacyValueAllowUsers (users = users ))
150- elif privacy == enums .StoriesPrivacyRules .SELECTED_USERS :
151- _allowed_users = []
152- _allowed_chats = []
153-
154- for user in allowed_users :
155- peer = await self .resolve_peer (user )
156- if isinstance (peer , raw .types .InputPeerUser ):
157- _allowed_users .append (peer )
158- elif isinstance (peer , raw .types .InputPeerChat ):
159- _allowed_chats .append (peer )
160-
161- if _allowed_users :
162- privacy_rules .append (raw .types .InputPrivacyValueAllowUsers (users = _allowed_users ))
163- if _allowed_chats :
164- privacy_rules .append (raw .types .InputPrivacyValueAllowChatParticipants (chats = _allowed_chats ))
165-
16699 try :
167100 if isinstance (media , str ):
168101 if os .path .isfile (media ):
@@ -213,52 +146,13 @@ async def edit_story(
213146 file = file ,
214147 )
215148
216- privacy_rules = []
217-
218- if privacy :
219- if privacy == enums .StoriesPrivacyRules .PUBLIC :
220- privacy_rules .append (raw .types .InputPrivacyValueAllowAll ())
221- if disallowed_users :
222- users = [await self .resolve_peer (user_id ) for user_id in disallowed_users ]
223- privacy_rules .append (raw .types .InputPrivacyValueDisallowUsers (users = users ))
224- elif privacy == enums .StoriesPrivacyRules .CONTACTS :
225- privacy_rules = [raw .types .InputPrivacyValueAllowContacts ()]
226- if disallowed_users :
227- users = [await self .resolve_peer (user_id ) for user_id in disallowed_users ]
228- privacy_rules .append (raw .types .InputPrivacyValueDisallowUsers (users = users ))
229- elif privacy == enums .StoriesPrivacyRules .CLOSE_FRIENDS :
230- privacy_rules = [raw .types .InputPrivacyValueAllowCloseFriends ()]
231- if allowed_users :
232- users = [await self .resolve_peer (user_id ) for user_id in allowed_users ]
233- privacy_rules .append (raw .types .InputPrivacyValueAllowUsers (users = users ))
234- elif privacy == enums .StoriesPrivacyRules .SELECTED_USERS :
235- _allowed_users = []
236- _allowed_chats = []
237-
238- for user in allowed_users :
239- peer = await self .resolve_peer (user )
240- if isinstance (peer , raw .types .InputPeerUser ):
241- _allowed_users .append (peer )
242- elif isinstance (peer , (raw .types .InputPeerChat , raw .types .InputPeerChannel )):
243- _allowed_chats .append (peer )
244-
245- if _allowed_users :
246- privacy_rules .append (raw .types .InputPrivacyValueAllowUsers (users = _allowed_users ))
247- if _allowed_chats :
248- privacy_rules .append (raw .types .InputPrivacyValueAllowChatParticipants (chats = _allowed_chats ))
249- else :
250- privacy_rules .append (raw .types .InputPrivacyValueAllowAll ())
251-
252149 while True :
253150 try :
254151 r = await self .invoke (
255152 raw .functions .stories .EditStory (
256153 peer = await self .resolve_peer (chat_id ),
257154 id = story_id ,
258155 media = media ,
259- caption = message ,
260- entities = entities ,
261- privacy_rules = privacy_rules ,
262156 )
263157 )
264158 except FilePartMissing as e :
0 commit comments