mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Fix stories types and obscure behavior (#77)
* Fix typos * Fix obscure undocumented behavior `edit_story_privacy` method by explicitly defaulting `privacy` parameter to `enums.StoriesPrivacyRules.PUBLIC`
This commit is contained in:
parent
1e0f5f85b3
commit
7f55351d89
@ -26,7 +26,7 @@ class EditStoryPrivacy:
|
||||
self: "pyrogram.Client",
|
||||
chat_id: Union[int, str],
|
||||
story_id: int,
|
||||
privacy: "enums.StoriesPrivacyRules" = None,
|
||||
privacy: "enums.StoriesPrivacyRules" = enums.StoriesPrivacyRules.PUBLIC,
|
||||
allowed_users: List[Union[int, str]] = None,
|
||||
disallowed_users: List[Union[int, str]] = None,
|
||||
) -> "types.Story":
|
||||
@ -44,7 +44,7 @@ class EditStoryPrivacy:
|
||||
Story identifier in the chat specified in chat_id.
|
||||
|
||||
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
|
||||
Story privacy.
|
||||
Story privacy. Defaults to :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`.
|
||||
|
||||
allowed_users (List of ``int`` | ``str``, *optional*):
|
||||
List of user_id or chat_id of chat users who are allowed to view stories.
|
||||
@ -76,39 +76,39 @@ class EditStoryPrivacy:
|
||||
"""
|
||||
privacy_rules = []
|
||||
|
||||
if privacy:
|
||||
if privacy == enums.StoriesPrivacyRules.PUBLIC:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowAll())
|
||||
if disallowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in disallowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueDisallowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.CONTACTS:
|
||||
privacy_rules = [raw.types.InputPrivacyValueAllowContacts()]
|
||||
if disallowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in disallowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueDisallowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.CLOSE_FRIENDS:
|
||||
privacy_rules = [raw.types.InputPrivacyValueAllowCloseFriends()]
|
||||
if allowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in allowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.SELECTED_USERS:
|
||||
_allowed_users = []
|
||||
_allowed_chats = []
|
||||
if not privacy:
|
||||
privacy = enums.StoriesPrivacyRules.PUBLIC
|
||||
|
||||
for user in allowed_users:
|
||||
peer = await self.resolve_peer(user)
|
||||
if isinstance(peer, raw.types.InputPeerUser):
|
||||
_allowed_users.append(peer)
|
||||
elif isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)):
|
||||
_allowed_chats.append(peer)
|
||||
|
||||
if _allowed_users:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=_allowed_users))
|
||||
if _allowed_chats:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=_allowed_chats))
|
||||
else:
|
||||
if privacy == enums.StoriesPrivacyRules.PUBLIC:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowAll())
|
||||
if disallowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in disallowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueDisallowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.CONTACTS:
|
||||
privacy_rules = [raw.types.InputPrivacyValueAllowContacts()]
|
||||
if disallowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in disallowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueDisallowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.CLOSE_FRIENDS:
|
||||
privacy_rules = [raw.types.InputPrivacyValueAllowCloseFriends()]
|
||||
if allowed_users:
|
||||
users = [await self.resolve_peer(user_id) for user_id in allowed_users]
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users))
|
||||
elif privacy == enums.StoriesPrivacyRules.SELECTED_USERS:
|
||||
_allowed_users = []
|
||||
_allowed_chats = []
|
||||
|
||||
for user in allowed_users:
|
||||
peer = await self.resolve_peer(user)
|
||||
if isinstance(peer, raw.types.InputPeerUser):
|
||||
_allowed_users.append(peer)
|
||||
elif isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)):
|
||||
_allowed_chats.append(peer)
|
||||
|
||||
if _allowed_users:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=_allowed_users))
|
||||
if _allowed_chats:
|
||||
privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=_allowed_chats))
|
||||
|
||||
|
||||
r = await self.invoke(
|
||||
|
@ -104,7 +104,7 @@ class Story(Object, Update):
|
||||
forwards (``int``, *optional*):
|
||||
Stories forwards.
|
||||
|
||||
privacy (:obj:`~pyrogram.enums.StoryPrivacyRules`, *optional*):
|
||||
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
|
||||
Story privacy.
|
||||
|
||||
allowed_users (List of ``int`` | ``str``, *optional*):
|
||||
@ -158,7 +158,7 @@ class Story(Object, Update):
|
||||
caption_entities: List["types.MessageEntity"] = None,
|
||||
views: int = None,
|
||||
forwards: int = None,
|
||||
privacy: "enums.StoryPrivacyRules" = None,
|
||||
privacy: "enums.StoriesPrivacyRules" = None,
|
||||
allowed_users: List[Union[int, str]] = None,
|
||||
disallowed_users: List[Union[int, str]] = None,
|
||||
reactions: List["types.Reaction"] = None,
|
||||
@ -1605,7 +1605,7 @@ class Story(Object, Update):
|
||||
|
||||
async def edit_privacy(
|
||||
self,
|
||||
privacy: "enums.StoriesPrivacyRules" = None,
|
||||
privacy: "enums.StoriesPrivacyRules" = enums.StoriesPrivacyRules.PUBLIC,
|
||||
allowed_users: List[Union[int, str]] = None,
|
||||
disallowed_users: List[Union[int, str]] = None,
|
||||
) -> "types.Story":
|
||||
@ -1627,7 +1627,7 @@ class Story(Object, Update):
|
||||
|
||||
Parameters:
|
||||
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
|
||||
Story privacy.
|
||||
Story privacy. Defaults to :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`.
|
||||
|
||||
allowed_users (List of ``int`` | ``str``, *optional*):
|
||||
List of user_id or chat_id of chat users who are allowed to view stories.
|
||||
|
Loading…
Reference in New Issue
Block a user