Skip to content

Commit be5f82e

Browse files
Remove edit_story method
1 parent fc0d9af commit be5f82e

6 files changed

Lines changed: 244 additions & 172 deletions

File tree

compiler/docs/compiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ def get_title_list(s: str) -> list:
350350
can_send_story
351351
copy_story
352352
delete_stories
353-
edit_story
353+
edit_story_caption
354+
edit_story_media
355+
edit_story_privacy
354356
export_story_link
355357
forward_story
356358
get_all_stories
@@ -671,7 +673,7 @@ def get_title_list(s: str) -> list:
671673
Story.reply_video_note
672674
Story.reply_voice
673675
Story.delete
674-
Story.edit
676+
Story.edit_media
675677
Story.edit_caption
676678
Story.edit_privacy
677679
Story.export_link

pyrogram/methods/stories/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from .can_send_story import CanSendStory
2020
from .copy_story import CopyStory
2121
from .delete_stories import DeleteStories
22-
from .edit_story import EditStory
22+
from .edit_story_caption import EditStoryCaption
23+
from .edit_story_media import EditStoryMedia
24+
from .edit_story_privacy import EditStoryPrivacy
2325
from .export_story_link import ExportStoryLink
2426
from .forward_story import ForwardStory
2527
from .get_all_stories import GetAllStories
@@ -37,7 +39,9 @@ class Stories(
3739
CanSendStory,
3840
CopyStory,
3941
DeleteStories,
40-
EditStory,
42+
EditStoryCaption,
43+
EditStoryMedia,
44+
EditStoryPrivacy,
4145
ExportStoryLink,
4246
ForwardStory,
4347
GetAllStories,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 List, Union
20+
21+
import pyrogram
22+
from pyrogram import enums, raw, types, utils
23+
24+
class EditStoryCaption:
25+
async def edit_story_caption(
26+
self: "pyrogram.Client",
27+
chat_id: Union[int, str],
28+
story_id: int,
29+
caption: str,
30+
parse_mode: "enums.ParseMode" = None,
31+
caption_entities: List["types.MessageEntity"] = None,
32+
) -> "types.Story":
33+
"""Edit the caption of story.
34+
35+
.. include:: /_includes/usable-by/users.rst
36+
37+
Parameters:
38+
chat_id (``int`` | ``str``):
39+
Unique identifier (int) or username (str) of the target chat.
40+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
41+
42+
story_id (``int``):
43+
Story identifier in the chat specified in chat_id.
44+
45+
caption (``str``):
46+
New caption of the story, 0-1024 characters.
47+
48+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
49+
By default, texts are parsed using both Markdown and HTML styles.
50+
You can combine both syntaxes together.
51+
52+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
53+
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
54+
55+
Returns:
56+
:obj:`~pyrogram.types.Story`: On success, the edited story is returned.
57+
58+
Example:
59+
.. code-block:: python
60+
61+
await app.edit_story(chat_id, story_id, "new media caption")
62+
"""
63+
64+
message, entities = (await utils.parse_text_entities(self, caption, parse_mode, caption_entities)).values()
65+
66+
r = await self.invoke(
67+
raw.functions.stories.EditStory(
68+
peer=await self.resolve_peer(chat_id),
69+
id=story_id,
70+
caption=message,
71+
entities=entities,
72+
)
73+
)
74+
75+
for i in r.updates:
76+
if isinstance(i, raw.types.UpdateStory):
77+
return await types.Story._parse(
78+
self,
79+
i.story,
80+
{i.id: i for i in r.users},
81+
{i.id: i for i in r.chats},
82+
i.peer
83+
)

pyrogram/methods/stories/edit_story.py renamed to pyrogram/methods/stories/edit_story_media.py

Lines changed: 13 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,45 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import os
20-
from typing import List, Union, BinaryIO, Callable
20+
from typing import Union, BinaryIO, Callable
2121

2222
import pyrogram
23-
from pyrogram import enums, raw, types, utils, StopTransmission
23+
from pyrogram import raw, types, utils, StopTransmission
2424
from 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

Comments
 (0)