feat: Can set admin title when promote a chat member.

This commit is contained in:
xiaocai 2024-06-13 15:43:35 +08:00
parent b4c6f66244
commit ed6dad7426
2 changed files with 26 additions and 11 deletions

View file

@ -17,7 +17,7 @@
# 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
from typing import Union, Optional
import pyrogram
from pyrogram import raw, types, errors
@ -25,10 +25,11 @@ from pyrogram import raw, types, errors
class PromoteChatMember:
async def promote_chat_member(
self: "pyrogram.Client",
chat_id: Union[int, str],
user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None,
self: "pyrogram.Client",
chat_id: Union[int, str],
user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None,
title: Optional[str] = None,
) -> bool:
"""Promote or demote a user in a supergroup or a channel.
@ -50,6 +51,11 @@ class PromoteChatMember:
privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
New user privileges.
title: (``str``, *optional*):
A custom title that will be shown to all members instead of "Owner" or "Admin".
Pass None or "" (empty string) will keep the current title.
If you want to delete the custom title, use :meth:`~pyrogram.Client.set_administrator_title()` method.
Returns:
``bool``: True on success.
@ -76,9 +82,10 @@ class PromoteChatMember:
except errors.RPCError:
raw_chat_member = None
rank = None
if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
if not title and isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
rank = raw_chat_member.rank
else:
rank = title
await self.invoke(
raw.functions.channels.EditAdmin(
@ -101,7 +108,7 @@ class PromoteChatMember:
delete_stories=privileges.can_delete_stories,
other=privileges.can_manage_chat
),
rank=rank or ""
rank=rank
)
)

View file

@ -953,7 +953,8 @@ class Chat(Object):
async def promote_member(
self,
user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None
privileges: "types.ChatPrivileges" = None,
title: Optional[str] = None,
) -> bool:
"""Bound method *promote_member* of :obj:`~pyrogram.types.Chat`.
@ -963,7 +964,8 @@ class Chat(Object):
await client.promote_chat_member(
chat_id=chat_id,
user_id=user_id
user_id=user_id,
title=admin_title
)
Example:
@ -980,6 +982,11 @@ class Chat(Object):
privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
New user privileges.
title (``str``, *optional*):
A custom title that will be shown to all members instead of "Owner" or "Admin".
Pass None or "" (empty string) will keep the current title.
If you want to delete the custom title, use :meth:`~pyrogram.Client.set_administrator_title()` method.
Returns:
``bool``: True on success.
@ -990,7 +997,8 @@ class Chat(Object):
return await self._client.promote_chat_member(
chat_id=self.id,
user_id=user_id,
privileges=privileges
privileges=privileges,
title=title
)
async def join(self):