mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Add set_custom_title method
This commit is contained in:
parent
5b27b952c4
commit
c0298542a5
@ -31,6 +31,7 @@ from .get_chat_members import GetChatMembers
|
||||
from .get_chat_members_count import GetChatMembersCount
|
||||
from .get_dialogs import GetDialogs
|
||||
from .get_dialogs_count import GetDialogsCount
|
||||
from .get_nearby_chats import GetNearbyChats
|
||||
from .iter_chat_members import IterChatMembers
|
||||
from .iter_dialogs import IterDialogs
|
||||
from .join_chat import JoinChat
|
||||
@ -43,11 +44,11 @@ from .set_chat_description import SetChatDescription
|
||||
from .set_chat_permissions import SetChatPermissions
|
||||
from .set_chat_photo import SetChatPhoto
|
||||
from .set_chat_title import SetChatTitle
|
||||
from .set_custom_title import SetCustomTitle
|
||||
from .unarchive_chats import UnarchiveChats
|
||||
from .unban_chat_member import UnbanChatMember
|
||||
from .unpin_chat_message import UnpinChatMessage
|
||||
from .update_chat_username import UpdateChatUsername
|
||||
from .get_nearby_chats import GetNearbyChats
|
||||
|
||||
|
||||
class Chats(
|
||||
@ -82,6 +83,7 @@ class Chats(
|
||||
AddChatMembers,
|
||||
DeleteChannel,
|
||||
DeleteSupergroup,
|
||||
GetNearbyChats
|
||||
GetNearbyChats,
|
||||
SetCustomTitle
|
||||
):
|
||||
pass
|
||||
|
@ -97,7 +97,8 @@ class PromoteChatMember(BaseClient):
|
||||
invite_users=can_invite_users or None,
|
||||
pin_messages=can_pin_messages or None,
|
||||
add_admins=can_promote_members or None,
|
||||
)
|
||||
),
|
||||
rank=""
|
||||
)
|
||||
)
|
||||
|
||||
|
90
pyrogram/client/methods/chats/set_custom_title.py
Normal file
90
pyrogram/client/methods/chats/set_custom_title.py
Normal file
@ -0,0 +1,90 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2019 Dan Tès <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/>.
|
||||
|
||||
from typing import Union
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
class SetCustomTitle(BaseClient):
|
||||
def set_custom_title(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
user_id: Union[int, str],
|
||||
title: str,
|
||||
) -> bool:
|
||||
"""Set a custom title to administrators or owners of a supergroup.
|
||||
|
||||
Parameters:
|
||||
chat_id (``int`` | ``str``):
|
||||
Unique identifier (int) or username (str) of the target chat.
|
||||
|
||||
user_id (``int`` | ``str``):
|
||||
Unique identifier (int) or username (str) of the target user.
|
||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||
|
||||
title (``str``, *optional*):
|
||||
A custom title that will be shown to all members instead of "Owner" or "Admin".
|
||||
Pass None or "" (empty string) to remove the custom title.
|
||||
|
||||
Returns:
|
||||
``bool``: True on success.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
# Set custom titles to owners or administrators of supergroups
|
||||
app.set_custom_title(chat_id, user_id, "Custom Title")
|
||||
"""
|
||||
chat_id = self.resolve_peer(chat_id)
|
||||
user_id = self.resolve_peer(user_id)
|
||||
|
||||
r = self.send(
|
||||
functions.channels.GetParticipant(
|
||||
channel=chat_id,
|
||||
user_id=user_id
|
||||
)
|
||||
).participant
|
||||
|
||||
if isinstance(r, types.ChannelParticipantCreator):
|
||||
admin_rights = types.ChatAdminRights(
|
||||
change_info=True,
|
||||
post_messages=True,
|
||||
edit_messages=True,
|
||||
delete_messages=True,
|
||||
ban_users=True,
|
||||
invite_users=True,
|
||||
pin_messages=True,
|
||||
add_admins=True,
|
||||
)
|
||||
elif isinstance(r, types.ChannelParticipantAdmin):
|
||||
admin_rights = r.admin_rights
|
||||
else:
|
||||
raise ValueError("Custom titles can only be applied to owners or administrators of supergroups")
|
||||
|
||||
self.send(
|
||||
functions.channels.EditAdmin(
|
||||
channel=chat_id,
|
||||
user_id=user_id,
|
||||
admin_rights=admin_rights,
|
||||
rank=title
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
Loading…
x
Reference in New Issue
Block a user