Add max_quantity to request_peer buttons

This commit is contained in:
KurimuzonAkuma 2023-12-24 10:50:48 +03:00
parent d8a760e9a8
commit 44e29da658
4 changed files with 62 additions and 14 deletions

View File

@ -59,7 +59,7 @@ class KeyboardButton(Object):
request_contact: bool = None, request_contact: bool = None,
request_location: bool = None, request_location: bool = None,
request_poll: "types.RequestPollInfo" = None, request_poll: "types.RequestPollInfo" = None,
request_peer: Union["types.RequestPeerTypeChannelInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None, request_peer: Union["types.RequestChannelInfo", "types.RequestChatInfo", "types.RequestUserInfo"] = None,
web_app: "types.WebAppInfo" = None, web_app: "types.WebAppInfo" = None,
): ):
super().__init__() super().__init__()
@ -95,10 +95,40 @@ class KeyboardButton(Object):
) )
if isinstance(b, raw.types.KeyboardButtonRequestPeer): if isinstance(b, raw.types.KeyboardButtonRequestPeer):
return KeyboardButton( if isinstance(b.peer_type, raw.types.RequestPeerTypeBroadcast):
text=b.text, return KeyboardButton(
request_peer=b.peer_type 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)
)
)
if isinstance(b.peer_type, raw.types.RequestPeerTypeChat):
return KeyboardButton(
text=b.text,
request_peer=types.RequestChatInfo(
button_id=b.button_id,
is_creator=getattr(b.peer_type, "creator", None),
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)
)
)
if isinstance(b.peer_type, raw.types.RequestPeerTypeUser):
return KeyboardButton(
text=b.text,
request_peer=types.RequestUserInfo(
button_id=b.button_id,
is_bot=getattr(b.peer_type, "bot", None),
is_premium=getattr(b.peer_type, "premium", None),
max_quantity=getattr(b, "max_quantity", None)
)
)
if isinstance(b, raw.types.KeyboardButtonSimpleWebView): if isinstance(b, raw.types.KeyboardButtonSimpleWebView):
return KeyboardButton( return KeyboardButton(
@ -126,7 +156,8 @@ class KeyboardButton(Object):
peer_type=raw.types.RequestPeerTypeBroadcast( peer_type=raw.types.RequestPeerTypeBroadcast(
creator=self.request_peer.is_creator, creator=self.request_peer.is_creator,
has_username=self.request_peer.has_username, has_username=self.request_peer.has_username,
) ),
max_quantity=self.request_peer.max_quantity
) )
if isinstance(self.request_peer, types.RequestChatInfo): if isinstance(self.request_peer, types.RequestChatInfo):
@ -138,7 +169,8 @@ class KeyboardButton(Object):
bot_participant=self.request_peer.is_bot_participant, bot_participant=self.request_peer.is_bot_participant,
has_username=self.request_peer.has_username, has_username=self.request_peer.has_username,
forum=self.request_peer.has_forum, forum=self.request_peer.has_forum,
) ),
max_quantity=self.request_peer.max_quantity
) )
if isinstance(self.request_peer, types.RequestUserInfo): if isinstance(self.request_peer, types.RequestUserInfo):
@ -148,7 +180,8 @@ class KeyboardButton(Object):
peer_type=raw.types.RequestPeerTypeUser( peer_type=raw.types.RequestPeerTypeUser(
bot=self.request_peer.is_bot, bot=self.request_peer.is_bot,
premium=self.request_peer.is_premium premium=self.request_peer.is_premium
) ),
max_quantity=self.request_peer.max_quantity
) )
elif self.web_app: elif self.web_app:

View File

@ -26,11 +26,14 @@ class RequestChannelInfo(Object):
button_id (``int``): button_id (``int``):
Identifier of button. Identifier of button.
is_creator (``bool``): is_creator (``bool``, *optional*):
If True, returns the list of chats where this user is a channel creator. If True, returns the list of chats where this user is a channel creator.
has_username (``bool``): has_username (``bool``, *optional*):
If True, returns the list of chats where chat has username. If True, returns the list of chats where chat has username.
max_quantity(``int``, *optional*):
Max quantity of peers.
""" """
def __init__( def __init__(
@ -38,9 +41,11 @@ class RequestChannelInfo(Object):
button_id: int, button_id: int,
is_creator: bool = None, is_creator: bool = None,
has_username: bool = None, has_username: bool = None,
max_quantity: int = None,
): ):
super().__init__() super().__init__()
self.button_id = button_id self.button_id = button_id
self.is_creator = is_creator self.is_creator = is_creator
self.has_username = has_username self.has_username = has_username
self.max_quantity = max_quantity

View File

@ -26,17 +26,20 @@ class RequestChatInfo(Object):
button_id (``int``): button_id (``int``):
Identifier of button. Identifier of button.
is_creator (``bool``): is_creator (``bool``, *optional*):
If True, returns the list of chats where this user is a chat creator. If True, returns the list of chats where this user is a chat creator.
is_bot_participant (``bool``): is_bot_participant (``bool``, *optional*):
If True, returns the list of chats where this bot is participant. If True, returns the list of chats where this bot is participant.
has_username (``bool``): has_username (``bool``, *optional*):
If True, returns the list of chats where chat has username. If True, returns the list of chats where chat has username.
has_forum (``bool``): 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.
""" """
def __init__( def __init__(
@ -46,6 +49,7 @@ class RequestChatInfo(Object):
is_bot_participant: bool = None, is_bot_participant: bool = None,
has_username: bool = None, has_username: bool = None,
has_forum: bool = None, has_forum: bool = None,
max_quantity: int = None,
): ):
super().__init__() super().__init__()
@ -55,3 +59,4 @@ class RequestChatInfo(Object):
self.is_bot_participant = is_bot_participant self.is_bot_participant = is_bot_participant
self.has_username = has_username self.has_username = has_username
self.has_forum = has_forum self.has_forum = has_forum
self.max_quantity = max_quantity

View File

@ -31,6 +31,9 @@ class RequestUserInfo(Object):
is_premium (``bool``, *optional*): is_premium (``bool``, *optional*):
If True, returns the list of users where user has premium. If True, returns the list of users where user has premium.
max_quantity(``int``, *optional*):
Max quantity of peers.
""" """
def __init__( def __init__(
@ -38,9 +41,11 @@ class RequestUserInfo(Object):
button_id: int, button_id: int,
is_bot: bool = None, is_bot: bool = None,
is_premium: bool = None, is_premium: bool = None,
max_quantity: int = None,
): ):
super().__init__() super().__init__()
self.button_id = button_id self.button_id = button_id
self.is_bot = is_bot self.is_bot = is_bot
self.is_premium = is_premium self.is_premium = is_premium
self.max_quantity = max_quantity