mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-28 00:56:19 +00:00
Fix requested_chat parsing and new buttons
This commit is contained in:
parent
9b6e59bef8
commit
293b3392e6
@ -485,10 +485,10 @@ def pyrogram_api():
|
|||||||
MenuButtonDefault
|
MenuButtonDefault
|
||||||
SentWebAppMessage
|
SentWebAppMessage
|
||||||
ForumTopic
|
ForumTopic
|
||||||
RequestPeerTypeBroadcastInfo
|
RequestChannelInfo
|
||||||
RequestPeerTypeChatInfo
|
RequestChatInfo
|
||||||
RequestPeerTypeUserInfo
|
RequestUserInfo
|
||||||
RequestPeerPollInfo
|
RequestPollInfo
|
||||||
""",
|
""",
|
||||||
bot_commands="""
|
bot_commands="""
|
||||||
Bot commands
|
Bot commands
|
||||||
|
@ -39,9 +39,9 @@ from .menu_button_default import MenuButtonDefault
|
|||||||
from .menu_button_web_app import MenuButtonWebApp
|
from .menu_button_web_app import MenuButtonWebApp
|
||||||
from .reply_keyboard_markup import ReplyKeyboardMarkup
|
from .reply_keyboard_markup import ReplyKeyboardMarkup
|
||||||
from .reply_keyboard_remove import ReplyKeyboardRemove
|
from .reply_keyboard_remove import ReplyKeyboardRemove
|
||||||
from .request_peer_broadcast_info import RequestPeerTypeBroadcastInfo
|
from .request_channel_info import RequestChannelInfo
|
||||||
from .request_peer_chat_info import RequestPeerTypeChatInfo
|
from .request_chat_info import RequestChatInfo
|
||||||
from .request_peer_user_info import RequestPeerTypeUserInfo
|
from .request_user_info import RequestUserInfo
|
||||||
from .request_poll_info import RequestPollInfo
|
from .request_poll_info import RequestPollInfo
|
||||||
from .sent_web_app_message import SentWebAppMessage
|
from .sent_web_app_message import SentWebAppMessage
|
||||||
from .web_app_info import WebAppInfo
|
from .web_app_info import WebAppInfo
|
||||||
@ -56,9 +56,9 @@ __all__ = [
|
|||||||
"KeyboardButton",
|
"KeyboardButton",
|
||||||
"ReplyKeyboardMarkup",
|
"ReplyKeyboardMarkup",
|
||||||
"ReplyKeyboardRemove",
|
"ReplyKeyboardRemove",
|
||||||
"RequestPeerTypeBroadcastInfo",
|
"RequestChannelInfo",
|
||||||
"RequestPeerTypeChatInfo",
|
"RequestChatInfo",
|
||||||
"RequestPeerTypeUserInfo",
|
"RequestUserInfo",
|
||||||
"RequestPollInfo",
|
"RequestPollInfo",
|
||||||
"LoginUrl",
|
"LoginUrl",
|
||||||
"BotCommand",
|
"BotCommand",
|
||||||
|
@ -43,7 +43,7 @@ class KeyboardButton(Object):
|
|||||||
request_poll (:obj:`~pyrogram.types.RequestPollInfo`, *optional*):
|
request_poll (:obj:`~pyrogram.types.RequestPollInfo`, *optional*):
|
||||||
If specified, the poll be sent when the button is pressed.
|
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.
|
If specified, the requested peer will be sent when the button is pressed.
|
||||||
|
|
||||||
web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*):
|
web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*):
|
||||||
@ -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.RequestPeerTypeBroadcastInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None,
|
request_peer: Union["types.RequestPeerTypeChannelInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None,
|
||||||
web_app: "types.WebAppInfo" = None,
|
web_app: "types.WebAppInfo" = None,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -115,9 +115,43 @@ 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_poll:
|
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:
|
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:
|
elif self.web_app:
|
||||||
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)
|
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)
|
||||||
else:
|
else:
|
||||||
|
@ -19,12 +19,15 @@
|
|||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
class RequestPeerTypeBroadcastInfo(Object):
|
class RequestChannelInfo(Object):
|
||||||
"""Contains information about a broadcast peer type.
|
"""Contains information about a channel peer type.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
button_id (``int``):
|
||||||
|
Identifier of button.
|
||||||
|
|
||||||
is_creator (``bool``):
|
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``):
|
has_username (``bool``):
|
||||||
If True, returns the list of chats where chat has username.
|
If True, returns the list of chats where chat has username.
|
||||||
@ -32,10 +35,12 @@ class RequestPeerTypeBroadcastInfo(Object):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, *,
|
self, *,
|
||||||
|
button_id: int,
|
||||||
is_creator: bool = None,
|
is_creator: bool = None,
|
||||||
has_username: bool = None,
|
has_username: bool = None,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
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
|
@ -19,10 +19,13 @@
|
|||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
class RequestPeerTypeChatInfo(Object):
|
class RequestChatInfo(Object):
|
||||||
"""Contains information about a chat peer type.
|
"""Contains information about a chat peer type.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
button_id (``int``):
|
||||||
|
Identifier of button.
|
||||||
|
|
||||||
is_creator (``bool``):
|
is_creator (``bool``):
|
||||||
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.
|
||||||
|
|
||||||
@ -38,6 +41,7 @@ class RequestPeerTypeChatInfo(Object):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, *,
|
self, *,
|
||||||
|
button_id: int,
|
||||||
is_creator: bool = None,
|
is_creator: bool = None,
|
||||||
is_bot_participant: bool = None,
|
is_bot_participant: bool = None,
|
||||||
has_username: bool = None,
|
has_username: bool = None,
|
||||||
@ -46,6 +50,7 @@ class RequestPeerTypeChatInfo(Object):
|
|||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
self.button_id = button_id
|
||||||
self.is_creator = is_creator
|
self.is_creator = is_creator
|
||||||
self.is_bot_participant = is_bot_participant
|
self.is_bot_participant = is_bot_participant
|
||||||
self.has_username = has_username
|
self.has_username = has_username
|
@ -20,7 +20,7 @@ from ..object import Object
|
|||||||
|
|
||||||
|
|
||||||
class RequestPollInfo(Object):
|
class RequestPollInfo(Object):
|
||||||
"""Contains information about a user peer type.
|
"""Contains information about a poll type.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
is_quiz (``bool``):
|
is_quiz (``bool``):
|
||||||
|
@ -19,23 +19,28 @@
|
|||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
class RequestPeerTypeUserInfo(Object):
|
class RequestUserInfo(Object):
|
||||||
"""Contains information about a user peer type.
|
"""Contains information about a user peer type.
|
||||||
|
|
||||||
Parameters:
|
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.
|
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.
|
If True, returns the list of users where user has premium.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, *,
|
self, *,
|
||||||
|
button_id: int,
|
||||||
is_bot: bool = None,
|
is_bot: bool = None,
|
||||||
is_premium: bool = None,
|
is_premium: bool = None,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
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
|
@ -352,7 +352,7 @@ class Message(Object, Update):
|
|||||||
gift_code (:obj:`~pyrogram.types.GiftCode`, *optional*):
|
gift_code (:obj:`~pyrogram.types.GiftCode`, *optional*):
|
||||||
Service message: gift code information.
|
Service message: gift code information.
|
||||||
|
|
||||||
requested_chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
requested_chat_id (``int``, *optional*):
|
||||||
Service message: requested chat information.
|
Service message: requested chat information.
|
||||||
|
|
||||||
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
|
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,
|
video_chat_members_invited: "types.VideoChatMembersInvited" = None,
|
||||||
web_app_data: "types.WebAppData" = None,
|
web_app_data: "types.WebAppData" = None,
|
||||||
gift_code: "types.GiftCode" = None,
|
gift_code: "types.GiftCode" = None,
|
||||||
requested_chat: "types.Chat" = None,
|
requested_chat_id: int = None,
|
||||||
giveaway_launched: bool = None,
|
giveaway_launched: bool = None,
|
||||||
reply_markup: Union[
|
reply_markup: Union[
|
||||||
"types.InlineKeyboardMarkup",
|
"types.InlineKeyboardMarkup",
|
||||||
@ -555,7 +555,7 @@ class Message(Object, Update):
|
|||||||
self.video_chat_members_invited = video_chat_members_invited
|
self.video_chat_members_invited = video_chat_members_invited
|
||||||
self.web_app_data = web_app_data
|
self.web_app_data = web_app_data
|
||||||
self.gift_code = gift_code
|
self.gift_code = gift_code
|
||||||
self.requested_chat = requested_chat
|
self.requested_chat_id = requested_chat_id
|
||||||
self.giveaway_launched = giveaway_launched
|
self.giveaway_launched = giveaway_launched
|
||||||
self.reactions = reactions
|
self.reactions = reactions
|
||||||
|
|
||||||
@ -619,7 +619,7 @@ class Message(Object, Update):
|
|||||||
web_app_data = None
|
web_app_data = None
|
||||||
gift_code = None
|
gift_code = None
|
||||||
giveaway_launched = None
|
giveaway_launched = None
|
||||||
requested_chat = None
|
requested_chat_id = None
|
||||||
|
|
||||||
service_type = None
|
service_type = None
|
||||||
|
|
||||||
@ -699,15 +699,7 @@ class Message(Object, Update):
|
|||||||
gift_code = types.GiftCode._parse(client, action, chats)
|
gift_code = types.GiftCode._parse(client, action, chats)
|
||||||
service_type = enums.MessageServiceType.GIFT_CODE
|
service_type = enums.MessageServiceType.GIFT_CODE
|
||||||
elif isinstance(action, raw.types.MessageActionRequestedPeer):
|
elif isinstance(action, raw.types.MessageActionRequestedPeer):
|
||||||
chat_id = utils.get_raw_peer_id(message.action.peer)
|
requested_chat_id = utils.get_peer_id(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])
|
|
||||||
service_type = enums.MessageServiceType.REQUESTED_CHAT
|
service_type = enums.MessageServiceType.REQUESTED_CHAT
|
||||||
|
|
||||||
from_user = types.User._parse(client, users.get(user_id, None))
|
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,
|
web_app_data=web_app_data,
|
||||||
giveaway_launched=giveaway_launched,
|
giveaway_launched=giveaway_launched,
|
||||||
gift_code=gift_code,
|
gift_code=gift_code,
|
||||||
requested_chat=requested_chat,
|
requested_chat_id=requested_chat_id,
|
||||||
client=client
|
client=client
|
||||||
# TODO: supergroup_chat_created
|
# TODO: supergroup_chat_created
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user