diff --git a/pyrogram/types/bots_and_keyboards/keyboard_button.py b/pyrogram/types/bots_and_keyboards/keyboard_button.py index 9f3c3192..3f70ff85 100644 --- a/pyrogram/types/bots_and_keyboards/keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/keyboard_button.py @@ -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 ) diff --git a/pyrogram/types/bots_and_keyboards/request_channel_info.py b/pyrogram/types/bots_and_keyboards/request_channel_info.py index 1bb4940b..407208a1 100644 --- a/pyrogram/types/bots_and_keyboards/request_channel_info.py +++ b/pyrogram/types/bots_and_keyboards/request_channel_info.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +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 diff --git a/pyrogram/types/bots_and_keyboards/request_chat_info.py b/pyrogram/types/bots_and_keyboards/request_chat_info.py index bd47c123..cd5ab91e 100644 --- a/pyrogram/types/bots_and_keyboards/request_chat_info.py +++ b/pyrogram/types/bots_and_keyboards/request_chat_info.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +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