Add support for joining linked chats with the .join() bound method
This commit is contained in:
parent
12ce0a33c1
commit
0556efa26b
@ -16,6 +16,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
@ -24,14 +26,14 @@ from ...ext import BaseClient
|
|||||||
class JoinChat(BaseClient):
|
class JoinChat(BaseClient):
|
||||||
def join_chat(
|
def join_chat(
|
||||||
self,
|
self,
|
||||||
chat_id: str
|
chat_id: Union[int, str]
|
||||||
):
|
):
|
||||||
"""Join a group chat or channel.
|
"""Join a group chat or channel.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
chat_id (``str``):
|
chat_id (``int`` | ``str``):
|
||||||
Unique identifier for the target chat in form of a *t.me/joinchat/* link or username of the target
|
Unique identifier for the target chat in form of a *t.me/joinchat/* link, a username of the target
|
||||||
channel/supergroup (in the format @username).
|
channel/supergroup (in the format @username) or a chat id of a linked chat (channel or supergroup).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Chat`: On success, a chat object is returned.
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
@ -44,8 +46,11 @@ class JoinChat(BaseClient):
|
|||||||
|
|
||||||
# Join chat via invite link
|
# Join chat via invite link
|
||||||
app.join_chat("https://t.me/joinchat/AAAAAE0QmSW3IUmm3UFR7A")
|
app.join_chat("https://t.me/joinchat/AAAAAE0QmSW3IUmm3UFR7A")
|
||||||
|
|
||||||
|
# Join a linked chat
|
||||||
|
app.join_chat(app.get_chat("pyrogram").linked_chat.id)
|
||||||
"""
|
"""
|
||||||
match = self.INVITE_LINK_RE.match(chat_id)
|
match = self.INVITE_LINK_RE.match(str(chat_id))
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
chat = self.send(
|
chat = self.send(
|
||||||
|
@ -675,7 +675,7 @@ class Chat(Object):
|
|||||||
chat.join()
|
chat.join()
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
This only works for public groups and channels that have set a username.
|
This only works for public groups, channels that have set a username or linked chats.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Chat`: On success, a chat object is returned.
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
@ -684,7 +684,7 @@ class Chat(Object):
|
|||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self._client.join_chat(self.username)
|
return self._client.join_chat(self.username or self.id)
|
||||||
|
|
||||||
def leave(self):
|
def leave(self):
|
||||||
"""Bound method *leave* of :obj:`Chat`.
|
"""Bound method *leave* of :obj:`Chat`.
|
||||||
|
Loading…
Reference in New Issue
Block a user