mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-05 23:04:51 +00:00
feat: Can set admin title when promote a chat member.
This commit is contained in:
parent
b4c6f66244
commit
ed6dad7426
2 changed files with 26 additions and 11 deletions
|
|
@ -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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue