mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 17:43:32 +00:00
Merge branch 'master' into docs
This commit is contained in:
commit
1cbb34f9b5
@ -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,
|
||||
@ -467,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".
|
||||
@ -510,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".
|
||||
@ -553,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".
|
||||
@ -619,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".
|
||||
@ -692,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".
|
||||
@ -754,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".
|
||||
@ -827,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".
|
||||
@ -893,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".
|
||||
@ -960,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".
|
||||
@ -1011,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".
|
||||
@ -1074,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".
|
||||
@ -1122,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".
|
||||
@ -1152,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):
|
||||
@ -1183,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".
|
||||
@ -1216,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".
|
||||
@ -1509,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).
|
||||
|
||||
@ -1545,33 +1546,64 @@ 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.
|
||||
|
||||
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).
|
||||
|
||||
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):
|
||||
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):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user