Fix requested_chat parsing and new buttons

This commit is contained in:
KurimuzonAkuma 2023-11-29 22:48:40 +03:00
parent 9b6e59bef8
commit 293b3392e6
8 changed files with 77 additions and 36 deletions

View File

@ -485,10 +485,10 @@ def pyrogram_api():
MenuButtonDefault
SentWebAppMessage
ForumTopic
RequestPeerTypeBroadcastInfo
RequestPeerTypeChatInfo
RequestPeerTypeUserInfo
RequestPeerPollInfo
RequestChannelInfo
RequestChatInfo
RequestUserInfo
RequestPollInfo
""",
bot_commands="""
Bot commands

View File

@ -39,9 +39,9 @@ from .menu_button_default import MenuButtonDefault
from .menu_button_web_app import MenuButtonWebApp
from .reply_keyboard_markup import ReplyKeyboardMarkup
from .reply_keyboard_remove import ReplyKeyboardRemove
from .request_peer_broadcast_info import RequestPeerTypeBroadcastInfo
from .request_peer_chat_info import RequestPeerTypeChatInfo
from .request_peer_user_info import RequestPeerTypeUserInfo
from .request_channel_info import RequestChannelInfo
from .request_chat_info import RequestChatInfo
from .request_user_info import RequestUserInfo
from .request_poll_info import RequestPollInfo
from .sent_web_app_message import SentWebAppMessage
from .web_app_info import WebAppInfo
@ -56,9 +56,9 @@ __all__ = [
"KeyboardButton",
"ReplyKeyboardMarkup",
"ReplyKeyboardRemove",
"RequestPeerTypeBroadcastInfo",
"RequestPeerTypeChatInfo",
"RequestPeerTypeUserInfo",
"RequestChannelInfo",
"RequestChatInfo",
"RequestUserInfo",
"RequestPollInfo",
"LoginUrl",
"BotCommand",

View File

@ -43,7 +43,7 @@ class KeyboardButton(Object):
request_poll (:obj:`~pyrogram.types.RequestPollInfo`, *optional*):
If specified, the poll be sent when the button is pressed.
request_peer (:obj:`~pyrogram.types.RequestPeerTypeBroadcastInfo` | :obj:`~pyrogram.types.RequestPeerTypeChatInfo` | :obj:`~pyrogram.types.RequestPeerTypeUserInfo`, *optional*):
request_peer (:obj:`~pyrogram.types.RequestPeerTypeChannelInfo` | :obj:`~pyrogram.types.RequestPeerTypeChatInfo` | :obj:`~pyrogram.types.RequestPeerTypeUserInfo`, *optional*):
If specified, the requested peer will be sent when the button is pressed.
web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*):
@ -59,7 +59,7 @@ class KeyboardButton(Object):
request_contact: bool = None,
request_location: bool = None,
request_poll: "types.RequestPollInfo" = None,
request_peer: Union["types.RequestPeerTypeBroadcastInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None,
request_peer: Union["types.RequestPeerTypeChannelInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None,
web_app: "types.WebAppInfo" = None,
):
super().__init__()
@ -115,9 +115,43 @@ class KeyboardButton(Object):
elif self.request_location:
return raw.types.KeyboardButtonRequestGeoLocation(text=self.text)
elif self.request_poll:
return raw.types.KeyboardButtonRequestPoll(text=self.text, quiz=self.quiz)
return raw.types.KeyboardButtonRequestPoll(
text=self.text,
quiz=self.request_poll.is_quiz
)
elif self.request_peer:
return raw.types.KeyboardButtonRequestPeer(text=self.text, button_id=self.button_id, peer_type=self.peer_type)
if isinstance(self.request_peer, types.RequestChannelInfo):
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,
)
)
if isinstance(self.request_peer, types.RequestChatInfo):
return raw.types.KeyboardButtonRequestPeer(
text=self.text,
button_id=self.request_peer.button_id,
peer_type=raw.types.RequestPeerTypeChat(
creator=self.request_peer.is_creator,
bot_participant=self.request_peer.is_bot_participant,
has_username=self.request_peer.has_username,
forum=self.request_peer.has_forum,
)
)
if isinstance(self.request_peer, types.RequestUserInfo):
return raw.types.KeyboardButtonRequestPeer(
text=self.text,
button_id=self.request_peer.button_id,
peer_type=raw.types.RequestPeerTypeUser(
bot=self.request_peer.is_bot,
premium=self.request_peer.is_premium
)
)
elif self.web_app:
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)
else:

View File

@ -19,12 +19,15 @@
from ..object import Object
class RequestPeerTypeBroadcastInfo(Object):
"""Contains information about a broadcast peer type.
class RequestChannelInfo(Object):
"""Contains information about a channel peer type.
Parameters:
button_id (``int``):
Identifier of button.
is_creator (``bool``):
If True, returns the list of chats where this user is a broadcast creator.
If True, returns the list of chats where this user is a channel creator.
has_username (``bool``):
If True, returns the list of chats where chat has username.
@ -32,10 +35,12 @@ class RequestPeerTypeBroadcastInfo(Object):
def __init__(
self, *,
button_id: int,
is_creator: bool = None,
has_username: bool = None,
):
super().__init__()
self.button_id = button_id
self.is_creator = is_creator
self.has_username = has_username

View File

@ -19,10 +19,13 @@
from ..object import Object
class RequestPeerTypeChatInfo(Object):
class RequestChatInfo(Object):
"""Contains information about a chat peer type.
Parameters:
button_id (``int``):
Identifier of button.
is_creator (``bool``):
If True, returns the list of chats where this user is a chat creator.
@ -38,6 +41,7 @@ class RequestPeerTypeChatInfo(Object):
def __init__(
self, *,
button_id: int,
is_creator: bool = None,
is_bot_participant: bool = None,
has_username: bool = None,
@ -46,6 +50,7 @@ class RequestPeerTypeChatInfo(Object):
):
super().__init__()
self.button_id = button_id
self.is_creator = is_creator
self.is_bot_participant = is_bot_participant
self.has_username = has_username

View File

@ -20,7 +20,7 @@ from ..object import Object
class RequestPollInfo(Object):
"""Contains information about a user peer type.
"""Contains information about a poll type.
Parameters:
is_quiz (``bool``):

View File

@ -19,23 +19,28 @@
from ..object import Object
class RequestPeerTypeUserInfo(Object):
class RequestUserInfo(Object):
"""Contains information about a user peer type.
Parameters:
is_bot (``bool``):
button_id (``int``):
Identifier of button.
is_bot (``bool``, *optional*):
If True, returns the list of users where user is a bot.
is_premium (``bool``):
is_premium (``bool``, *optional*):
If True, returns the list of users where user has premium.
"""
def __init__(
self, *,
button_id: int,
is_bot: bool = None,
is_premium: bool = None,
):
super().__init__()
self.button_id = button_id
self.is_bot = is_bot
self.is_premium = is_premium

View File

@ -352,7 +352,7 @@ class Message(Object, Update):
gift_code (:obj:`~pyrogram.types.GiftCode`, *optional*):
Service message: gift code information.
requested_chat (:obj:`~pyrogram.types.Chat`, *optional*):
requested_chat_id (``int``, *optional*):
Service message: requested chat information.
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
@ -457,7 +457,7 @@ class Message(Object, Update):
video_chat_members_invited: "types.VideoChatMembersInvited" = None,
web_app_data: "types.WebAppData" = None,
gift_code: "types.GiftCode" = None,
requested_chat: "types.Chat" = None,
requested_chat_id: int = None,
giveaway_launched: bool = None,
reply_markup: Union[
"types.InlineKeyboardMarkup",
@ -555,7 +555,7 @@ class Message(Object, Update):
self.video_chat_members_invited = video_chat_members_invited
self.web_app_data = web_app_data
self.gift_code = gift_code
self.requested_chat = requested_chat
self.requested_chat_id = requested_chat_id
self.giveaway_launched = giveaway_launched
self.reactions = reactions
@ -619,7 +619,7 @@ class Message(Object, Update):
web_app_data = None
gift_code = None
giveaway_launched = None
requested_chat = None
requested_chat_id = None
service_type = None
@ -699,15 +699,7 @@ class Message(Object, Update):
gift_code = types.GiftCode._parse(client, action, chats)
service_type = enums.MessageServiceType.GIFT_CODE
elif isinstance(action, raw.types.MessageActionRequestedPeer):
chat_id = utils.get_raw_peer_id(message.action.peer)
if isinstance(message.peer_id, raw.types.PeerUser):
requested_chat = types.Chat._parse_user_chat(client, users[chat_id])
if isinstance(message.peer_id, raw.types.PeerChat):
requested_chat = types.Chat._parse_chat_chat(client, chats[chat_id])
requested_chat = types.Chat._parse_channel_chat(client, chats[chat_id])
requested_chat_id = utils.get_peer_id(action.peer)
service_type = enums.MessageServiceType.REQUESTED_CHAT
from_user = types.User._parse(client, users.get(user_id, None))
@ -744,7 +736,7 @@ class Message(Object, Update):
web_app_data=web_app_data,
giveaway_launched=giveaway_launched,
gift_code=gift_code,
requested_chat=requested_chat,
requested_chat_id=requested_chat_id,
client=client
# TODO: supergroup_chat_created
)