mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
pyrofork: Add privileges to RequestPeer buttons
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
6fbae9b037
commit
e5ccb0f36e
3 changed files with 94 additions and 20 deletions
|
|
@ -99,15 +99,21 @@ class KeyboardButton(Object):
|
||||||
|
|
||||||
if isinstance(b, raw.types.KeyboardButtonRequestPeer):
|
if isinstance(b, raw.types.KeyboardButtonRequestPeer):
|
||||||
if isinstance(b.peer_type, raw.types.RequestPeerTypeBroadcast):
|
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(
|
return KeyboardButton(
|
||||||
text=b.text,
|
text=b.text,
|
||||||
request_chat=types.RequestPeerTypeChannel(
|
request_chat=types.RequestPeerTypeChannel(
|
||||||
is_creator=b.peer_type.creator,
|
is_creator=b.peer_type.creator,
|
||||||
is_username=b.peer_type.has_username,
|
is_username=b.peer_type.has_username,
|
||||||
max=b.max_quantity
|
max=b.max_quantity,
|
||||||
|
user_privileges=user_privileges,
|
||||||
|
bot_privileges=bot_privileges
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if isinstance(b.peer_type, raw.types.RequestPeerTypeChat):
|
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(
|
return KeyboardButton(
|
||||||
text=b.text,
|
text=b.text,
|
||||||
request_chat=types.RequestPeerTypeChat(
|
request_chat=types.RequestPeerTypeChat(
|
||||||
|
|
@ -115,7 +121,9 @@ class KeyboardButton(Object):
|
||||||
is_bot_participant=b.peer_type.bot_participant,
|
is_bot_participant=b.peer_type.bot_participant,
|
||||||
is_username=b.peer_type.has_username,
|
is_username=b.peer_type.has_username,
|
||||||
is_forum=b.peer_type.forum,
|
is_forum=b.peer_type.forum,
|
||||||
max=b.max_quantity
|
max=b.max_quantity,
|
||||||
|
user_privileges=user_privileges,
|
||||||
|
bot_privileges=bot_privileges
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -135,13 +143,52 @@ class KeyboardButton(Object):
|
||||||
elif self.request_location:
|
elif self.request_location:
|
||||||
return raw.types.KeyboardButtonRequestGeoLocation(text=self.text)
|
return raw.types.KeyboardButtonRequestGeoLocation(text=self.text)
|
||||||
elif self.request_chat:
|
elif self.request_chat:
|
||||||
|
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
|
||||||
|
|
||||||
if isinstance(self.request_chat, types.RequestPeerTypeChannel):
|
if isinstance(self.request_chat, types.RequestPeerTypeChannel):
|
||||||
return raw.types.InputKeyboardButtonRequestPeer(
|
return raw.types.InputKeyboardButtonRequestPeer(
|
||||||
text=self.text,
|
text=self.text,
|
||||||
button_id=self.request_chat.button_id,
|
button_id=self.request_chat.button_id,
|
||||||
peer_type=raw.types.RequestPeerTypeBroadcast(
|
peer_type=raw.types.RequestPeerTypeBroadcast(
|
||||||
creator=self.request_chat.is_creator,
|
creator=self.request_chat.is_creator,
|
||||||
has_username=self.request_chat.is_username
|
has_username=self.request_chat.is_username,
|
||||||
|
user_admin_rights=user_admin_rights,
|
||||||
|
bot_admin_rights=bot_admin_rights
|
||||||
),
|
),
|
||||||
max_quantity=self.request_chat.max,
|
max_quantity=self.request_chat.max,
|
||||||
name_requested=self.request_chat.is_name_requested,
|
name_requested=self.request_chat.is_name_requested,
|
||||||
|
|
@ -155,7 +202,9 @@ class KeyboardButton(Object):
|
||||||
creator=self.request_chat.is_creator,
|
creator=self.request_chat.is_creator,
|
||||||
bot_participant=self.request_chat.is_bot_participant,
|
bot_participant=self.request_chat.is_bot_participant,
|
||||||
has_username=self.request_chat.is_username,
|
has_username=self.request_chat.is_username,
|
||||||
forum=self.request_chat.is_forum
|
forum=self.request_chat.is_forum,
|
||||||
|
user_admin_rights=user_admin_rights,
|
||||||
|
bot_admin_rights=bot_admin_rights
|
||||||
),
|
),
|
||||||
max_quantity=self.request_chat.max,
|
max_quantity=self.request_chat.max,
|
||||||
name_requested=self.request_chat.is_name_requested,
|
name_requested=self.request_chat.is_name_requested,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
# 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 pyrogram import types
|
||||||
|
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -47,17 +49,25 @@ class RequestPeerTypeChannel(Object):
|
||||||
is_photo_requested (``bool``, *optional*):
|
is_photo_requested (``bool``, *optional*):
|
||||||
If True, Channel photo is requested.
|
If True, Channel photo is requested.
|
||||||
default True.
|
default True.
|
||||||
|
|
||||||
|
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 a bot administrator is able to take.
|
||||||
""" # TODO user_admin_rights, bot_admin_rights
|
""" # TODO user_admin_rights, bot_admin_rights
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
button_id: int=0,
|
button_id: int = 0,
|
||||||
is_creator: bool=None,
|
is_creator: bool = None,
|
||||||
is_username: bool=None,
|
is_username: bool = None,
|
||||||
max: int=1,
|
max: int = 1,
|
||||||
is_name_requested: bool=True,
|
is_name_requested: bool = True,
|
||||||
is_username_requested: bool=True,
|
is_username_requested: bool = True,
|
||||||
is_photo_requested: bool=True
|
is_photo_requested: bool = True,
|
||||||
|
user_privileges: "types.ChatPrivileges" = None,
|
||||||
|
bot_privileges: "types.ChatPrivileges" = None
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
@ -68,3 +78,6 @@ class RequestPeerTypeChannel(Object):
|
||||||
self.is_name_requested = is_name_requested
|
self.is_name_requested = is_name_requested
|
||||||
self.is_username_requested = is_username_requested
|
self.is_username_requested = is_username_requested
|
||||||
self.is_photo_requested = is_photo_requested
|
self.is_photo_requested = is_photo_requested
|
||||||
|
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
|
# 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 pyrogram import types
|
||||||
|
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,19 +55,27 @@ class RequestPeerTypeChat(Object):
|
||||||
is_photo_requested (``bool``, *optional*):
|
is_photo_requested (``bool``, *optional*):
|
||||||
If True, Chat photo is requested.
|
If True, Chat photo is requested.
|
||||||
default True.
|
default True.
|
||||||
|
|
||||||
|
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 a bot administrator is able to take.
|
||||||
""" # TODO user_admin_rights, bot_admin_rights
|
""" # TODO user_admin_rights, bot_admin_rights
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
button_id: int=0,
|
button_id: int = 0,
|
||||||
is_creator: bool=None,
|
is_creator: bool = None,
|
||||||
is_bot_participant: bool=None,
|
is_bot_participant: bool = None,
|
||||||
is_username: bool=None,
|
is_username: bool = None,
|
||||||
is_forum: bool=None,
|
is_forum: bool = None,
|
||||||
max: int=1,
|
max: int = 1,
|
||||||
is_name_requested: bool=True,
|
is_name_requested: bool = True,
|
||||||
is_username_requested: bool=True,
|
is_username_requested: bool = True,
|
||||||
is_photo_requested: bool=True
|
is_photo_requested: bool = True,
|
||||||
|
user_privileges: "types.ChatPrivileges" = None,
|
||||||
|
bot_privileges: "types.ChatPrivileges" = None
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
@ -78,3 +88,5 @@ class RequestPeerTypeChat(Object):
|
||||||
self.is_name_requested = is_name_requested
|
self.is_name_requested = is_name_requested
|
||||||
self.is_username_requested = is_username_requested
|
self.is_username_requested = is_username_requested
|
||||||
self.is_photo_requested = is_photo_requested
|
self.is_photo_requested = is_photo_requested
|
||||||
|
self.user_privileges = user_privileges
|
||||||
|
self.bot_privileges = bot_privileges
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue