Merge pull request #74 from X1A0CA1/main

Improved promote_chat_member() method and Doc Fix
This commit is contained in:
2024-06-15 14:54:55 +07:00 committed by GitHub
commit caf61d8dab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 12 deletions

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
from typing import Union from typing import Union, Optional
import pyrogram import pyrogram
from pyrogram import raw, types, errors from pyrogram import raw, types, errors
@ -25,10 +25,11 @@ from pyrogram import raw, types, errors
class PromoteChatMember: class PromoteChatMember:
async def promote_chat_member( async def promote_chat_member(
self: "pyrogram.Client", self: "pyrogram.Client",
chat_id: Union[int, str], chat_id: Union[int, str],
user_id: Union[int, str], user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None, privileges: "types.ChatPrivileges" = None,
title: Optional[str] = None,
) -> bool: ) -> bool:
"""Promote or demote a user in a supergroup or a channel. """Promote or demote a user in a supergroup or a channel.
@ -50,6 +51,11 @@ class PromoteChatMember:
privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*): privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
New user privileges. 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: Returns:
``bool``: True on success. ``bool``: True on success.
@ -76,9 +82,10 @@ class PromoteChatMember:
except errors.RPCError: except errors.RPCError:
raw_chat_member = None raw_chat_member = None
rank = None if not title and isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
rank = raw_chat_member.rank rank = raw_chat_member.rank
else:
rank = title
await self.invoke( await self.invoke(
raw.functions.channels.EditAdmin( raw.functions.channels.EditAdmin(
@ -101,7 +108,7 @@ class PromoteChatMember:
delete_stories=privileges.can_delete_stories, delete_stories=privileges.can_delete_stories,
other=privileges.can_manage_chat other=privileges.can_manage_chat
), ),
rank=rank or "" rank=rank
) )
) )

View file

@ -39,7 +39,7 @@ class Run:
operation. This is almost the same as :py:obj:`asyncio.run` except for the fact that Pyrogram's ``run`` uses the operation. This is almost the same as :py:obj:`asyncio.run` except for the fact that Pyrogram's ``run`` uses the
current event loop instead of a new one. current event loop instead of a new one.
If you want to run multiple clients at once, see :meth:`pyrogram.compose`. If you want to run multiple clients at once, see :meth:`~pyrogram.compose`.
Parameters: Parameters:
coroutine (``Coroutine``, *optional*): coroutine (``Coroutine``, *optional*):

View file

@ -953,7 +953,8 @@ class Chat(Object):
async def promote_member( async def promote_member(
self, self,
user_id: Union[int, str], user_id: Union[int, str],
privileges: "types.ChatPrivileges" = None privileges: "types.ChatPrivileges" = None,
title: Optional[str] = None,
) -> bool: ) -> bool:
"""Bound method *promote_member* of :obj:`~pyrogram.types.Chat`. """Bound method *promote_member* of :obj:`~pyrogram.types.Chat`.
@ -963,7 +964,8 @@ class Chat(Object):
await client.promote_chat_member( await client.promote_chat_member(
chat_id=chat_id, chat_id=chat_id,
user_id=user_id user_id=user_id,
title=admin_title
) )
Example: Example:
@ -980,6 +982,11 @@ class Chat(Object):
privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*): privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
New user privileges. 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: Returns:
``bool``: True on success. ``bool``: True on success.
@ -990,7 +997,8 @@ class Chat(Object):
return await self._client.promote_chat_member( return await self._client.promote_chat_member(
chat_id=self.id, chat_id=self.id,
user_id=user_id, user_id=user_id,
privileges=privileges privileges=privileges,
title=title
) )
async def join(self): async def join(self):