diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index f737c821..f262a6b3 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -285,6 +285,7 @@ def pyrogram_api(): hide_general_topic reopen_forum_topic reopen_general_topic + transfer_chat_ownership unhide_general_topic update_color update_folder diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 267a05a9..4ec5fd10 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -67,6 +67,7 @@ from .set_chat_title import SetChatTitle from .set_chat_username import SetChatUsername from .set_send_as_chat import SetSendAsChat from .set_slow_mode import SetSlowMode +from .transfer_chat_ownership import TransferChatOwnership from .unarchive_chats import UnarchiveChats from .unban_chat_member import UnbanChatMember from .unpin_all_chat_messages import UnpinAllChatMessages @@ -130,6 +131,7 @@ class Chats( GetSendAsChats, SetSendAsChat, SetChatProtectedContent, + TransferChatOwnership, UpdateColor, UpdateFolder ): diff --git a/pyrogram/methods/chats/transfer_chat_ownership.py b/pyrogram/methods/chats/transfer_chat_ownership.py new file mode 100644 index 00000000..78b23ac2 --- /dev/null +++ b/pyrogram/methods/chats/transfer_chat_ownership.py @@ -0,0 +1,83 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from typing import Union +import pyrogram +from pyrogram import raw, utils + + +class TransferChatOwnership: + async def transfer_chat_ownership( + self: "pyrogram.Client", + chat_id: Union[int, str], + user_id: Union[int, str], + password: str, + ) -> bool: + """Transfer the owner of a chat or channel to another user. + + .. note: + + Requires owner privileges. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + Unique identifier for the target chat in form of a *t.me/joinchat/* link, identifier (int) or username + of the target channel/supergroup (in the format @username). + + user_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the new owner. + For a contact that exists in your Telegram address book you can use his phone number (str). + + password (``str``): + The 2-step verification password of the current user. + + Returns: + ``bool``: True on success. + + Raises: + ValueError: In case of invalid parameters. + RPCError: In case of a Telegram RPC error. + + Example: + .. code-block:: python + + await app.transfer_chat_ownership(chat_id, user_id, "password") + """ + peer_channel = await self.resolve_peer(chat_id) + peer_user = await self.resolve_peer(user_id) + + if not isinstance(peer_channel, raw.types.InputPeerChannel): + raise ValueError("The chat_id must belong to a channel/supergroup.") + + if not isinstance(peer_user, raw.types.InputPeerUser): + raise ValueError("The user_id must belong to a user.") + + r = await self.invoke( + raw.functions.channels.EditCreator( + channel=peer_channel, + user_id=peer_user, + password=utils.compute_password_check( + await self.invoke(raw.functions.account.GetPassword()), password + ), + ) + ) + + return bool(r)