mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add privileges to RequestPeer buttons
This commit is contained in:
parent
5d9031c2c0
commit
0a383924f9
@ -96,17 +96,25 @@ class KeyboardButton(Object):
|
||||
|
||||
if isinstance(b, raw.types.KeyboardButtonRequestPeer):
|
||||
if isinstance(b.peer_type, raw.types.RequestPeerTypeBroadcast):
|
||||
user_privileges = getattr(b.peer_type, "user_admin_rights", None)
|
||||
bot_privileges = getattr(b.peer_type, "bot_admin_rights", None)
|
||||
|
||||
return KeyboardButton(
|
||||
text=b.text,
|
||||
request_peer=types.RequestChannelInfo(
|
||||
button_id=b.button_id,
|
||||
is_creator=getattr(b.peer_type, "creator", None),
|
||||
has_username=getattr(b.peer_type, "has_username", None),
|
||||
max_quantity=getattr(b, "max_quantity", None)
|
||||
max_quantity=getattr(b, "max_quantity", None),
|
||||
user_privileges=types.ChatPrivileges._parse(user_privileges) if user_privileges else None,
|
||||
bot_privileges=types.ChatPrivileges._parse(bot_privileges) if bot_privileges else None
|
||||
)
|
||||
)
|
||||
|
||||
if isinstance(b.peer_type, raw.types.RequestPeerTypeChat):
|
||||
user_privileges = getattr(b.peer_type, "user_admin_rights", None)
|
||||
bot_privileges = getattr(b.peer_type, "bot_admin_rights", None)
|
||||
|
||||
return KeyboardButton(
|
||||
text=b.text,
|
||||
request_peer=types.RequestChatInfo(
|
||||
@ -115,7 +123,9 @@ class KeyboardButton(Object):
|
||||
is_bot_participant=getattr(b.peer_type, "bot_participant", None),
|
||||
has_username=getattr(b.peer_type, "has_username", None),
|
||||
has_forum=getattr(b.peer_type, "forum", None),
|
||||
max_quantity=getattr(b, "max_quantity", None)
|
||||
max_quantity=getattr(b, "max_quantity", None),
|
||||
user_privileges=types.ChatPrivileges._parse(user_privileges) if user_privileges else None,
|
||||
bot_privileges=types.ChatPrivileges._parse(bot_privileges) if bot_privileges else None
|
||||
)
|
||||
)
|
||||
|
||||
@ -150,17 +160,93 @@ class KeyboardButton(Object):
|
||||
)
|
||||
elif self.request_peer:
|
||||
if isinstance(self.request_peer, types.RequestChannelInfo):
|
||||
user_privileges = self.request_peer.user_privileges
|
||||
bot_privileges = self.request_peer.bot_privileges
|
||||
|
||||
user_admin_rights = raw.types.ChatAdminRights(
|
||||
change_info=user_privileges.can_change_info,
|
||||
post_messages=user_privileges.can_post_messages,
|
||||
post_stories=user_privileges.can_post_stories,
|
||||
edit_messages=user_privileges.can_edit_messages,
|
||||
edit_stories=user_privileges.can_post_stories,
|
||||
delete_messages=user_privileges.can_delete_messages,
|
||||
delete_stories=user_privileges.can_delete_stories,
|
||||
ban_users=user_privileges.can_restrict_members,
|
||||
invite_users=user_privileges.can_invite_users,
|
||||
pin_messages=user_privileges.can_pin_messages,
|
||||
add_admins=user_privileges.can_promote_members,
|
||||
anonymous=user_privileges.is_anonymous,
|
||||
manage_call=user_privileges.can_manage_video_chats,
|
||||
other=user_privileges.can_manage_chat
|
||||
) if user_privileges else None
|
||||
|
||||
bot_admin_rights = raw.types.ChatAdminRights(
|
||||
change_info=bot_privileges.can_change_info,
|
||||
post_messages=bot_privileges.can_post_messages,
|
||||
post_stories=bot_privileges.can_post_stories,
|
||||
edit_messages=bot_privileges.can_edit_messages,
|
||||
edit_stories=bot_privileges.can_post_stories,
|
||||
delete_messages=bot_privileges.can_delete_messages,
|
||||
delete_stories=bot_privileges.can_delete_stories,
|
||||
ban_users=bot_privileges.can_restrict_members,
|
||||
invite_users=bot_privileges.can_invite_users,
|
||||
pin_messages=bot_privileges.can_pin_messages,
|
||||
add_admins=bot_privileges.can_promote_members,
|
||||
anonymous=bot_privileges.is_anonymous,
|
||||
manage_call=bot_privileges.can_manage_video_chats,
|
||||
other=bot_privileges.can_manage_chat
|
||||
) if bot_privileges else None
|
||||
|
||||
return raw.types.KeyboardButtonRequestPeer(
|
||||
text=self.text,
|
||||
button_id=self.request_peer.button_id,
|
||||
peer_type=raw.types.RequestPeerTypeBroadcast(
|
||||
creator=self.request_peer.is_creator,
|
||||
has_username=self.request_peer.has_username,
|
||||
user_admin_rights=user_admin_rights,
|
||||
bot_admin_rights=bot_admin_rights
|
||||
),
|
||||
max_quantity=self.request_peer.max_quantity
|
||||
)
|
||||
|
||||
if isinstance(self.request_peer, types.RequestChatInfo):
|
||||
user_privileges = self.request_peer.user_privileges
|
||||
bot_privileges = self.request_peer.bot_privileges
|
||||
|
||||
user_admin_rights = raw.types.ChatAdminRights(
|
||||
change_info=user_privileges.can_change_info,
|
||||
post_messages=user_privileges.can_post_messages,
|
||||
post_stories=user_privileges.can_post_stories,
|
||||
edit_messages=user_privileges.can_edit_messages,
|
||||
edit_stories=user_privileges.can_post_stories,
|
||||
delete_messages=user_privileges.can_delete_messages,
|
||||
delete_stories=user_privileges.can_delete_stories,
|
||||
ban_users=user_privileges.can_restrict_members,
|
||||
invite_users=user_privileges.can_invite_users,
|
||||
pin_messages=user_privileges.can_pin_messages,
|
||||
add_admins=user_privileges.can_promote_members,
|
||||
anonymous=user_privileges.is_anonymous,
|
||||
manage_call=user_privileges.can_manage_video_chats,
|
||||
other=user_privileges.can_manage_chat
|
||||
) if user_privileges else None
|
||||
|
||||
bot_admin_rights = raw.types.ChatAdminRights(
|
||||
change_info=bot_privileges.can_change_info,
|
||||
post_messages=bot_privileges.can_post_messages,
|
||||
post_stories=bot_privileges.can_post_stories,
|
||||
edit_messages=bot_privileges.can_edit_messages,
|
||||
edit_stories=bot_privileges.can_post_stories,
|
||||
delete_messages=bot_privileges.can_delete_messages,
|
||||
delete_stories=bot_privileges.can_delete_stories,
|
||||
ban_users=bot_privileges.can_restrict_members,
|
||||
invite_users=bot_privileges.can_invite_users,
|
||||
pin_messages=bot_privileges.can_pin_messages,
|
||||
add_admins=bot_privileges.can_promote_members,
|
||||
anonymous=bot_privileges.is_anonymous,
|
||||
manage_call=bot_privileges.can_manage_video_chats,
|
||||
other=bot_privileges.can_manage_chat
|
||||
) if bot_privileges else None
|
||||
|
||||
return raw.types.KeyboardButtonRequestPeer(
|
||||
text=self.text,
|
||||
button_id=self.request_peer.button_id,
|
||||
@ -169,6 +255,8 @@ class KeyboardButton(Object):
|
||||
bot_participant=self.request_peer.is_bot_participant,
|
||||
has_username=self.request_peer.has_username,
|
||||
forum=self.request_peer.has_forum,
|
||||
user_admin_rights=user_admin_rights,
|
||||
bot_admin_rights=bot_admin_rights
|
||||
),
|
||||
max_quantity=self.request_peer.max_quantity
|
||||
)
|
||||
|
@ -16,6 +16,8 @@
|
||||
# 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 pyrogram import types
|
||||
|
||||
from ..object import Object
|
||||
|
||||
|
||||
@ -34,6 +36,12 @@ class RequestChannelInfo(Object):
|
||||
|
||||
max_quantity(``int``, *optional*):
|
||||
Max quantity of peers.
|
||||
|
||||
user_privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
|
||||
Privileged actions that an user administrator is able to take.
|
||||
|
||||
bot_privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
|
||||
Privileged actions that an bot administrator is able to take.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@ -42,6 +50,8 @@ class RequestChannelInfo(Object):
|
||||
is_creator: bool = None,
|
||||
has_username: bool = None,
|
||||
max_quantity: int = None,
|
||||
user_privileges: "types.ChatPrivileges" = None,
|
||||
bot_privileges: "types.ChatPrivileges" = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
@ -49,3 +59,5 @@ class RequestChannelInfo(Object):
|
||||
self.is_creator = is_creator
|
||||
self.has_username = has_username
|
||||
self.max_quantity = max_quantity
|
||||
self.user_privileges = user_privileges
|
||||
self.bot_privileges = bot_privileges
|
||||
|
@ -16,6 +16,8 @@
|
||||
# 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 pyrogram import types
|
||||
|
||||
from ..object import Object
|
||||
|
||||
|
||||
@ -36,10 +38,16 @@ class RequestChatInfo(Object):
|
||||
If True, returns the list of chats where chat has username.
|
||||
|
||||
has_forum (``bool``, *optional*):
|
||||
If True, returns the list of chats where forum topcis is enabled.
|
||||
If True, returns the list of chats where forum topcis is enabled.
|
||||
|
||||
max_quantity(``int``, *optional*):
|
||||
Max quantity of peers.
|
||||
|
||||
user_privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
|
||||
Privileged actions that an user administrator is able to take.
|
||||
|
||||
bot_privileges (:obj:`~pyrogram.types.ChatPrivileges`, *optional*):
|
||||
Privileged actions that an bot administrator is able to take.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@ -50,7 +58,8 @@ class RequestChatInfo(Object):
|
||||
has_username: bool = None,
|
||||
has_forum: bool = None,
|
||||
max_quantity: int = None,
|
||||
|
||||
user_privileges: "types.ChatPrivileges" = None,
|
||||
bot_privileges: "types.ChatPrivileges" = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
@ -60,3 +69,5 @@ class RequestChatInfo(Object):
|
||||
self.has_username = has_username
|
||||
self.has_forum = has_forum
|
||||
self.max_quantity = max_quantity
|
||||
self.user_privileges = user_privileges
|
||||
self.bot_privileges = bot_privileges
|
||||
|
Loading…
Reference in New Issue
Block a user