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,
|
PhoneMigrate, NetworkMigrate, PhoneNumberInvalid,
|
||||||
PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty,
|
PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty,
|
||||||
PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded,
|
PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded,
|
||||||
PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing
|
PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing,
|
||||||
|
ChatAdminRequired
|
||||||
)
|
)
|
||||||
from pyrogram.api.types import (
|
from pyrogram.api.types import (
|
||||||
User, Chat, Channel,
|
User, Chat, Channel,
|
||||||
@ -467,7 +468,7 @@ class Client:
|
|||||||
"""Use this method to send text messages.
|
"""Use this method to send text messages.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -510,12 +511,12 @@ class Client:
|
|||||||
"""Use this method to forward messages of any kind.
|
"""Use this method to forward messages of any kind.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
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
|
Unique identifier for the chat where the original message was sent
|
||||||
(or channel/supergroup username in the format @username). For your personal cloud
|
(or channel/supergroup username in the format @username). For your personal cloud
|
||||||
storage (Saved Messages) you can simply use "me" or "self".
|
storage (Saved Messages) you can simply use "me" or "self".
|
||||||
@ -553,7 +554,7 @@ class Client:
|
|||||||
"""Use this method to send photos.
|
"""Use this method to send photos.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -619,7 +620,7 @@ class Client:
|
|||||||
For sending voice messages, use the :obj:`send_voice` method instead.
|
For sending voice messages, use the :obj:`send_voice` method instead.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -692,7 +693,7 @@ class Client:
|
|||||||
"""Use this method to send general files.
|
"""Use this method to send general files.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -754,7 +755,7 @@ class Client:
|
|||||||
"""Use this method to send video files.
|
"""Use this method to send video files.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -827,7 +828,7 @@ class Client:
|
|||||||
"""Use this method to send audio files.
|
"""Use this method to send audio files.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -893,7 +894,7 @@ class Client:
|
|||||||
"""Use this method to send video messages.
|
"""Use this method to send video messages.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -960,7 +961,7 @@ class Client:
|
|||||||
"""Use this method to send points on the map.
|
"""Use this method to send points on the map.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -1011,7 +1012,7 @@ class Client:
|
|||||||
"""Use this method to send information about a venue.
|
"""Use this method to send information about a venue.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -1074,7 +1075,7 @@ class Client:
|
|||||||
"""Use this method to send phone contacts.
|
"""Use this method to send phone contacts.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
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.
|
"""Use this method when you need to tell the other party that something is happening on your side.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -1152,7 +1153,7 @@ class Client:
|
|||||||
"""Use this method to get a list of profile pictures for a user.
|
"""Use this method to get a list of profile pictures for a user.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id (:obj:`int` | :obj:`str`):
|
user_id (:obj:`int` or :obj:`str`):
|
||||||
Unique identifier of the target user.
|
Unique identifier of the target user.
|
||||||
|
|
||||||
offset (:obj:`int`, optional):
|
offset (:obj:`int`, optional):
|
||||||
@ -1183,7 +1184,7 @@ class Client:
|
|||||||
"""Use this method to edit text messages.
|
"""Use this method to edit text messages.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -1216,7 +1217,7 @@ class Client:
|
|||||||
"""Use this method to edit captions of messages.
|
"""Use this method to edit captions of messages.
|
||||||
|
|
||||||
Args:
|
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
|
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
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
simply use "me" or "self".
|
simply use "me" or "self".
|
||||||
@ -1509,7 +1510,7 @@ class Client:
|
|||||||
"""Use this method to leave a group chat or channel.
|
"""Use this method to leave a group chat or channel.
|
||||||
|
|
||||||
Args:
|
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
|
Unique identifier for the target chat or username of the target channel/supergroup
|
||||||
(in the format @username).
|
(in the format @username).
|
||||||
|
|
||||||
@ -1545,33 +1546,64 @@ class Client:
|
|||||||
|
|
||||||
return r
|
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.
|
"""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.
|
The user must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||||
|
|
||||||
Args:
|
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
|
Unique identifier for the target chat or username of the target channel/supergroup
|
||||||
(in the format @username).
|
(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:
|
Returns:
|
||||||
On success, the exported invite link as string is returned.
|
On success, the exported invite link as string is returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`pyrogram.Error`
|
: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)
|
peer = self.resolve_peer(chat_id)
|
||||||
|
|
||||||
if isinstance(peer, types.InputPeerChat):
|
if isinstance(peer, types.InputPeerChat):
|
||||||
|
if new:
|
||||||
return self.send(
|
return self.send(
|
||||||
functions.messages.ExportChatInvite(
|
functions.messages.ExportChatInvite(
|
||||||
chat_id=peer.chat_id
|
chat_id=peer.chat_id
|
||||||
)
|
)
|
||||||
).link
|
).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):
|
elif isinstance(peer, types.InputPeerChannel):
|
||||||
|
if new:
|
||||||
return self.send(
|
return self.send(
|
||||||
functions.channels.ExportInvite(
|
functions.channels.ExportInvite(
|
||||||
channel=peer
|
channel=peer
|
||||||
)
|
)
|
||||||
).link
|
).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