From 44d1679108b09a239815f6a848618bc984b2dabe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 8 Jan 2018 06:31:48 +0100 Subject: [PATCH 1/2] Add ability to export current links without revoking the old ones --- pyrogram/client/client.py | 56 ++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 5aaa5203..88703652 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -36,7 +36,8 @@ from pyrogram.api.errors import ( PhoneMigrate, NetworkMigrate, PhoneNumberInvalid, PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty, PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, - PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing + PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, + ChatAdminRequired ) from pyrogram.api.types import ( User, Chat, Channel, @@ -1545,7 +1546,7 @@ class Client: return r - def export_chat_invite_link(self, chat_id: int or str): + def export_chat_invite_link(self, chat_id: int or str, new: bool = False): """Use this method to export an invite link to a supergroup or a channel. The user must be an administrator in the chat for this to work and must have the appropriate admin rights. @@ -1555,23 +1556,54 @@ class Client: Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). + new (:obj:`bool`): + The previous link will be deactivated and a new link will be generated. + This is also used to create the invite link in case it doesn't exist yet. + Returns: On success, the exported invite link as string is returned. Raises: :class:`pyrogram.Error` + + Note: + If the returned link is a new one it may take a while for it to be activated. """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): - return self.send( - functions.messages.ExportChatInvite( - chat_id=peer.chat_id - ) - ).link + if new: + return self.send( + functions.messages.ExportChatInvite( + chat_id=peer.chat_id + ) + ).link + else: + chat_full = self.send( + functions.messages.GetFullChat( + chat_id=peer.chat_id + ) + ).full_chat # type: types.ChatFull + + if isinstance(chat_full.exported_invite, types.ChatInviteExported): + return chat_full.exported_invite.link + else: + raise ChatAdminRequired elif isinstance(peer, types.InputPeerChannel): - return self.send( - functions.channels.ExportInvite( - channel=peer - ) - ).link + if new: + return self.send( + functions.channels.ExportInvite( + channel=peer + ) + ).link + else: + channel_full = self.send( + functions.channels.GetFullChannel( + channel=peer + ) + ).full_chat # type: types.ChannelFull + + if isinstance(channel_full.exported_invite, types.ChatInviteExported): + return channel_full.exported_invite.link + else: + raise ChatAdminRequired From ead7573d33132b63e7e4a83c56f4eb06593e1824 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 8 Jan 2018 06:34:49 +0100 Subject: [PATCH 2/2] Replace "|" with "or" --- pyrogram/client/client.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 88703652..c6aea2a1 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -468,7 +468,7 @@ class Client: """Use this method to send text messages. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -511,12 +511,12 @@ class Client: """Use this method to forward messages of any kind. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". - from_chat_id (:obj:`int` | :obj:`str`): + from_chat_id (:obj:`int` or :obj:`str`): Unique identifier for the chat where the original message was sent (or channel/supergroup username in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -554,7 +554,7 @@ class Client: """Use this method to send photos. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -620,7 +620,7 @@ class Client: For sending voice messages, use the :obj:`send_voice` method instead. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -693,7 +693,7 @@ class Client: """Use this method to send general files. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -755,7 +755,7 @@ class Client: """Use this method to send video files. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -828,7 +828,7 @@ class Client: """Use this method to send audio files. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -894,7 +894,7 @@ class Client: """Use this method to send video messages. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -961,7 +961,7 @@ class Client: """Use this method to send points on the map. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1012,7 +1012,7 @@ class Client: """Use this method to send information about a venue. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1075,7 +1075,7 @@ class Client: """Use this method to send phone contacts. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1123,7 +1123,7 @@ class Client: """Use this method when you need to tell the other party that something is happening on your side. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1153,7 +1153,7 @@ class Client: """Use this method to get a list of profile pictures for a user. Args: - user_id (:obj:`int` | :obj:`str`): + user_id (:obj:`int` or :obj:`str`): Unique identifier of the target user. offset (:obj:`int`, optional): @@ -1184,7 +1184,7 @@ class Client: """Use this method to edit text messages. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1217,7 +1217,7 @@ class Client: """Use this method to edit captions of messages. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). For your personal cloud storage (Saved Messages) you can simply use "me" or "self". @@ -1510,7 +1510,7 @@ class Client: """Use this method to leave a group chat or channel. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). @@ -1552,7 +1552,7 @@ class Client: The user must be an administrator in the chat for this to work and must have the appropriate admin rights. Args: - chat_id (:obj:`int` | :obj:`str`): + chat_id (:obj:`int` or :obj:`str`): Unique identifier for the target chat or username of the target channel/supergroup (in the format @username).