diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index bb9e0286f..99f3e96bf 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -40,6 +40,8 @@ from .menu_button_web_app import MenuButtonWebApp from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove +from .request_peer_type_chat import RequestPeerTypeChat +from .request_peer_type_user import RequestPeerTypeUser from .sent_web_app_message import SentWebAppMessage from .web_app_info import WebAppInfo @@ -53,6 +55,8 @@ "KeyboardButton", "ReplyKeyboardMarkup", "ReplyKeyboardRemove", + "RequestPeerTypeChat", + "RequestPeerTypeUser", "LoginUrl", "BotCommand", "BotCommandScope", diff --git a/pyrogram/types/bots_and_keyboards/keyboard_button.py b/pyrogram/types/bots_and_keyboards/keyboard_button.py index 5c8d4b733..d25d3d8af 100644 --- a/pyrogram/types/bots_and_keyboards/keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/keyboard_button.py @@ -38,6 +38,14 @@ class KeyboardButton(Object): If True, the user's current location will be sent when the button is pressed. Available in private chats only. + request_chat ("obj:`~pyrogram.types.RequestPeerTypeChat`, *optional*): + If specified, defines the criteria used to request a suitable chats. + The identifier of the selected chats will be shared with the bot when the corresponding button is pressed. + + request_user ("obj:`~pyrogram.types.RequestPeerTypeUser`, *optional*): + If specified, defines the criteria used to request a suitable users. + The identifier of the selected users will be shared with the bot when the corresponding button is pressed. + web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*): If specified, the described `Web App `_ will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private @@ -50,6 +58,8 @@ def __init__( text: str, request_contact: bool = None, request_location: bool = None, + request_chat: "types.RequestPeerTypeChat" = None, + request_user: "types.RequestPeerTypeUser" = None, web_app: "types.WebAppInfo" = None ): super().__init__() @@ -57,6 +67,8 @@ def __init__( self.text = str(text) self.request_contact = request_contact self.request_location = request_location + self.request_chat = request_chat + self.request_user = request_user self.web_app = web_app @staticmethod @@ -84,11 +96,51 @@ def read(b): ) ) + if isinstance(b, raw.types.RequestPeerTypeChat): + return KeyboardButton( + text=b.text, + request_chat=types.RequestPeerTypeChat( + is_creator=b.creator, + is_bot_participant=b.bot_participant, + is_username=b.has_username, + is_forum=b.forum + ) + ) + + if isinstance(b, raw.types.RequestPeerTypeUser): + return KeyboardButton( + text=b.text, + request_user=types.RequestPeerTypeUser( + is_bot=b.bot, + is_premium=b.premium + ) + ) + def write(self): if self.request_contact: return raw.types.KeyboardButtonRequestPhone(text=self.text) elif self.request_location: return raw.types.KeyboardButtonRequestGeoLocation(text=self.text) + elif self.request_chat: + return raw.types.KeyboardButtonRequestPeer( + text=self.text, + button_id=0, + peer_type=raw.types.RequestPeerTypeChat( + creator=self.request_chat.is_creator, + bot_participant=self.request_chat.is_bot_participant, + has_username=self.request_chat.is_username, + forum=self.request_chat.is_forum + ) + ) + elif self.request_user: + return raw.types.KeyboardButtonRequestPeer( + text=self.text, + button_id=0, + peer_type=raw.types.RequestPeerTypeUser( + bot=self.request_user.is_bot, + premium=self.request_user.is_premium + ) + ) elif self.web_app: return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url) else: diff --git a/pyrogram/types/bots_and_keyboards/request_peer_type_chat.py b/pyrogram/types/bots_and_keyboards/request_peer_type_chat.py new file mode 100644 index 000000000..96d812ab1 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/request_peer_type_chat.py @@ -0,0 +1,53 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from pyrogram import raw + +from ..object import Object + + +class RequestPeerTypeChat(Object): + """A bot Information. + + Parameters: + is_creator (``bool``, *optional*): + If True, show only Chat which user is the owner. + + is_bot_participant (``bool``, *optional*): + If True, show only Chat where bot is a participant. + + is_username (``bool``, *optional*): + If True, show only Chat which has username. + + is_forum (``bool``, *optional*): + If True, show only Chat which is a forum. + """ # TODO user_admin_rights, bot_admin_rights + + def __init__( + self, + is_creator: bool=None, + is_bot_participant: bool=None, + is_username: bool=None, + is_forum: bool=None + ): + super().__init__() + + self.is_creator = is_creator + self.is_bot_participant = is_bot_participant + self.is_username = is_username + self.is_forum = is_forum diff --git a/pyrogram/types/bots_and_keyboards/request_peer_type_user.py b/pyrogram/types/bots_and_keyboards/request_peer_type_user.py new file mode 100644 index 000000000..3d77dbebd --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/request_peer_type_user.py @@ -0,0 +1,43 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from pyrogram import raw + +from ..object import Object + + +class RequestPeerTypeUser(Object): + """A bot Information. + + Parameters: + is_bot (``bool``, *optional*): + If True, show only Bots. + + is_premium (``bool``, *optional*): + If True, show only Premium Users. + """ + + def __init__( + self, + is_bot: bool=None, + is_premium: bool=None + ): + super().__init__() + + self.is_bot = is_bot + self.is_premium = is_premium