mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
Pyrofork: Add request_chat and request_user parameters to KeyboardButton class
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
c3a61812ef
commit
9299b9bd7d
5 changed files with 150 additions and 0 deletions
|
|
@ -459,6 +459,8 @@ def pyrogram_api():
|
||||||
ReplyKeyboardRemove
|
ReplyKeyboardRemove
|
||||||
InlineKeyboardMarkup
|
InlineKeyboardMarkup
|
||||||
InlineKeyboardButton
|
InlineKeyboardButton
|
||||||
|
RequestPeerTypeChat
|
||||||
|
RequestPeerTypeUser
|
||||||
LoginUrl
|
LoginUrl
|
||||||
ForceReply
|
ForceReply
|
||||||
CallbackQuery
|
CallbackQuery
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ 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_type_chat import RequestPeerTypeChat
|
||||||
|
from .request_peer_type_user import RequestPeerTypeUser
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -53,6 +55,8 @@ __all__ = [
|
||||||
"KeyboardButton",
|
"KeyboardButton",
|
||||||
"ReplyKeyboardMarkup",
|
"ReplyKeyboardMarkup",
|
||||||
"ReplyKeyboardRemove",
|
"ReplyKeyboardRemove",
|
||||||
|
"RequestPeerTypeChat",
|
||||||
|
"RequestPeerTypeUser",
|
||||||
"LoginUrl",
|
"LoginUrl",
|
||||||
"BotCommand",
|
"BotCommand",
|
||||||
"BotCommandScope",
|
"BotCommandScope",
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,14 @@ class KeyboardButton(Object):
|
||||||
If True, the user's current location will be sent when the button is pressed.
|
If True, the user's current location will be sent when the button is pressed.
|
||||||
Available in private chats only.
|
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*):
|
web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*):
|
||||||
If specified, the described `Web App <https://core.telegram.org/bots/webapps>`_ will be launched when the
|
If specified, the described `Web App <https://core.telegram.org/bots/webapps>`_ 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
|
button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private
|
||||||
|
|
@ -50,6 +58,8 @@ class KeyboardButton(Object):
|
||||||
text: str,
|
text: str,
|
||||||
request_contact: bool = None,
|
request_contact: bool = None,
|
||||||
request_location: bool = None,
|
request_location: bool = None,
|
||||||
|
request_chat: "types.RequestPeerTypeChat" = None,
|
||||||
|
request_user: "types.RequestPeerTypeUser" = None,
|
||||||
web_app: "types.WebAppInfo" = None
|
web_app: "types.WebAppInfo" = None
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -57,6 +67,8 @@ class KeyboardButton(Object):
|
||||||
self.text = str(text)
|
self.text = str(text)
|
||||||
self.request_contact = request_contact
|
self.request_contact = request_contact
|
||||||
self.request_location = request_location
|
self.request_location = request_location
|
||||||
|
self.request_chat = request_chat
|
||||||
|
self.request_user = request_user
|
||||||
self.web_app = web_app
|
self.web_app = web_app
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -84,11 +96,51 @@ class KeyboardButton(Object):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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):
|
def write(self):
|
||||||
if self.request_contact:
|
if self.request_contact:
|
||||||
return raw.types.KeyboardButtonRequestPhone(text=self.text)
|
return raw.types.KeyboardButtonRequestPhone(text=self.text)
|
||||||
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:
|
||||||
|
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:
|
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:
|
||||||
|
|
|
||||||
51
pyrogram/types/bots_and_keyboards/request_peer_type_chat.py
Normal file
51
pyrogram/types/bots_and_keyboards/request_peer_type_chat.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class RequestPeerTypeChat(Object):
|
||||||
|
"""Object used to request clients to send a chat identifier.
|
||||||
|
|
||||||
|
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
|
||||||
41
pyrogram/types/bots_and_keyboards/request_peer_type_user.py
Normal file
41
pyrogram/types/bots_and_keyboards/request_peer_type_user.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class RequestPeerTypeUser(Object):
|
||||||
|
"""Object used to request clients to send a user identifier.
|
||||||
|
|
||||||
|
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
|
||||||
Loading…
Reference in a new issue