mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add new methods join/leave_folder
This commit is contained in:
parent
e4121e5d61
commit
618d19aad6
@ -252,6 +252,8 @@ def pyrogram_api():
|
|||||||
get_folders
|
get_folders
|
||||||
update_folder
|
update_folder
|
||||||
get_similar_channels
|
get_similar_channels
|
||||||
|
join_folder
|
||||||
|
leave_folder
|
||||||
""",
|
""",
|
||||||
users="""
|
users="""
|
||||||
Users
|
Users
|
||||||
|
@ -47,7 +47,9 @@ from .get_forum_topics_by_id import GetForumTopicsByID
|
|||||||
from .get_nearby_chats import GetNearbyChats
|
from .get_nearby_chats import GetNearbyChats
|
||||||
from .get_send_as_chats import GetSendAsChats
|
from .get_send_as_chats import GetSendAsChats
|
||||||
from .join_chat import JoinChat
|
from .join_chat import JoinChat
|
||||||
|
from .join_folder import JoinFolder
|
||||||
from .leave_chat import LeaveChat
|
from .leave_chat import LeaveChat
|
||||||
|
from .leave_folder import LeaveFolder
|
||||||
from .mark_chat_unread import MarkChatUnread
|
from .mark_chat_unread import MarkChatUnread
|
||||||
from .pin_chat_message import PinChatMessage
|
from .pin_chat_message import PinChatMessage
|
||||||
from .promote_chat_member import PromoteChatMember
|
from .promote_chat_member import PromoteChatMember
|
||||||
@ -75,7 +77,9 @@ from .update_folder import UpdateFolder
|
|||||||
class Chats(
|
class Chats(
|
||||||
GetChat,
|
GetChat,
|
||||||
LeaveChat,
|
LeaveChat,
|
||||||
|
LeaveFolder,
|
||||||
JoinChat,
|
JoinChat,
|
||||||
|
JoinFolder,
|
||||||
BanChatMember,
|
BanChatMember,
|
||||||
UnbanChatMember,
|
UnbanChatMember,
|
||||||
RestrictChatMember,
|
RestrictChatMember,
|
||||||
|
75
pyrogram/methods/chats/join_folder.py
Normal file
75
pyrogram/methods/chats/join_folder.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, utils
|
||||||
|
|
||||||
|
|
||||||
|
class JoinFolder:
|
||||||
|
async def join_folder(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
link: str,
|
||||||
|
) -> bool:
|
||||||
|
"""Join a folder by its invite link.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
link (``str``):
|
||||||
|
Invite link of the folder.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: True, on success.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
BadRequest: In case the folder invite link not exists.
|
||||||
|
ValueError: In case the folder invite link is invalid.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# join folder
|
||||||
|
app.join_folder("t.me/addlist/ebXQ0Q0I3RnGQ")
|
||||||
|
"""
|
||||||
|
match = re.match(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:addlist/|\+))([\w-]+)$", link)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
raise ValueError("Invalid folder invite link")
|
||||||
|
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.chatlists.CheckChatlistInvite(
|
||||||
|
slug=match.group(1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(r, raw.types.chatlists.ChatlistInviteAlready):
|
||||||
|
peers = r.already_peers + r.missing_peers
|
||||||
|
else:
|
||||||
|
peers = r.peers
|
||||||
|
|
||||||
|
await self.invoke(
|
||||||
|
raw.functions.chatlists.JoinChatlistInvite(
|
||||||
|
slug=match.group(1),
|
||||||
|
peers=[
|
||||||
|
await self.resolve_peer(utils.get_peer_id(id)) for id in peers
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
79
pyrogram/methods/chats/leave_folder.py
Normal file
79
pyrogram/methods/chats/leave_folder.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, utils
|
||||||
|
|
||||||
|
|
||||||
|
class LeaveFolder:
|
||||||
|
async def leave_folder(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
link: str,
|
||||||
|
keep_chats: bool = True
|
||||||
|
) -> bool:
|
||||||
|
"""Leave a folder by its invite link.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
link (``str``):
|
||||||
|
Invite link of the folder.
|
||||||
|
|
||||||
|
keep_chats (``bool``, *optional*):
|
||||||
|
If True, the chats from the folder will be kept in the user's account.
|
||||||
|
Defaults to True.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: True, on success.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
AttributeError: In case the folder invite link does not exist in the user's account.
|
||||||
|
BadRequest: In case the folder invite link not exists.
|
||||||
|
ValueError: In case the folder invite link is invalid.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# leave folder
|
||||||
|
app.leave_folder("t.me/addlist/ebXQ0Q0I3RnGQ")
|
||||||
|
"""
|
||||||
|
match = re.match(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:addlist/|\+))([\w-]+)$", link)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
raise ValueError("Invalid folder invite link")
|
||||||
|
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.chatlists.CheckChatlistInvite(
|
||||||
|
slug=match.group(1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await self.invoke(
|
||||||
|
raw.functions.chatlists.LeaveChatlist(
|
||||||
|
chatlist=raw.types.InputChatlistDialogFilter(
|
||||||
|
filter_id=r.filter_id
|
||||||
|
),
|
||||||
|
peers=[
|
||||||
|
await self.resolve_peer(utils.get_peer_id(id))
|
||||||
|
for id in r.already_peers
|
||||||
|
] if not keep_chats else [],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
Loading…
Reference in New Issue
Block a user