mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add transfer_chat_ownership method (#145)
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
07bdefb017
commit
621c690e55
3 changed files with 86 additions and 0 deletions
|
|
@ -285,6 +285,7 @@ def pyrogram_api():
|
||||||
hide_general_topic
|
hide_general_topic
|
||||||
reopen_forum_topic
|
reopen_forum_topic
|
||||||
reopen_general_topic
|
reopen_general_topic
|
||||||
|
transfer_chat_ownership
|
||||||
unhide_general_topic
|
unhide_general_topic
|
||||||
update_color
|
update_color
|
||||||
update_folder
|
update_folder
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ from .set_chat_title import SetChatTitle
|
||||||
from .set_chat_username import SetChatUsername
|
from .set_chat_username import SetChatUsername
|
||||||
from .set_send_as_chat import SetSendAsChat
|
from .set_send_as_chat import SetSendAsChat
|
||||||
from .set_slow_mode import SetSlowMode
|
from .set_slow_mode import SetSlowMode
|
||||||
|
from .transfer_chat_ownership import TransferChatOwnership
|
||||||
from .unarchive_chats import UnarchiveChats
|
from .unarchive_chats import UnarchiveChats
|
||||||
from .unban_chat_member import UnbanChatMember
|
from .unban_chat_member import UnbanChatMember
|
||||||
from .unpin_all_chat_messages import UnpinAllChatMessages
|
from .unpin_all_chat_messages import UnpinAllChatMessages
|
||||||
|
|
@ -130,6 +131,7 @@ class Chats(
|
||||||
GetSendAsChats,
|
GetSendAsChats,
|
||||||
SetSendAsChat,
|
SetSendAsChat,
|
||||||
SetChatProtectedContent,
|
SetChatProtectedContent,
|
||||||
|
TransferChatOwnership,
|
||||||
UpdateColor,
|
UpdateColor,
|
||||||
UpdateFolder
|
UpdateFolder
|
||||||
):
|
):
|
||||||
|
|
|
||||||
83
pyrogram/methods/chats/transfer_chat_ownership.py
Normal file
83
pyrogram/methods/chats/transfer_chat_ownership.py
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
Loading…
Reference in a new issue