Add new keyboard buttons

This commit is contained in:
KurimuzonAkuma 2023-11-29 18:19:48 +03:00
parent af4cb18e30
commit 5802ed8422
7 changed files with 212 additions and 1 deletions

View File

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

View File

@ -39,6 +39,10 @@ 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_poll_info import RequestPollInfo
from .sent_web_app_message import SentWebAppMessage
from .web_app_info import WebAppInfo
@ -52,6 +56,10 @@ __all__ = [
"KeyboardButton",
"ReplyKeyboardMarkup",
"ReplyKeyboardRemove",
"RequestPeerTypeBroadcastInfo",
"RequestPeerTypeChatInfo",
"RequestPeerTypeUserInfo",
"RequestPollInfo",
"LoginUrl",
"BotCommand",
"BotCommandScope",

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram import raw, types
from ..object import Object
@ -38,6 +40,12 @@ class KeyboardButton(Object):
If True, the user's current location will be sent when the button is pressed.
Available in private chats only.
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*):
If specified, the requested peer will be sent when the button is pressed.
web_app (:obj:`~pyrogram.types.WebAppInfo`, *optional*):
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
@ -50,13 +58,17 @@ class KeyboardButton(Object):
text: str,
request_contact: bool = None,
request_location: bool = None,
web_app: "types.WebAppInfo" = None
request_poll: "types.RequestPollInfo" = None,
request_peer: Union["types.RequestPeerTypeBroadcastInfo", "types.RequestPeerTypeChatInfo", "types.RequestPeerTypeUserInfo"] = None,
web_app: "types.WebAppInfo" = None,
):
super().__init__()
self.text = str(text)
self.request_contact = request_contact
self.request_location = request_location
self.request_poll = request_poll
self.request_peer = request_peer
self.web_app = web_app
@staticmethod
@ -76,6 +88,19 @@ class KeyboardButton(Object):
request_location=True
)
if isinstance(b, raw.types.KeyboardButtonRequestPoll):
return KeyboardButton(
text=b.text,
quiz=b.quiz
)
if isinstance(b, raw.types.KeyboardButtonRequestPeer):
return KeyboardButton(
text=b.text,
button_id=b.button_id,
peer_type=b.peer_type
)
if isinstance(b, raw.types.KeyboardButtonSimpleWebView):
return KeyboardButton(
text=b.text,
@ -89,6 +114,10 @@ class KeyboardButton(Object):
return raw.types.KeyboardButtonRequestPhone(text=self.text)
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)
elif self.request_peer:
return raw.types.KeyboardButtonRequestPeer(text=self.text, button_id=self.button_id, peer_type=self.peer_type)
elif self.web_app:
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)
else:

View File

@ -0,0 +1,41 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from ..object import Object
class RequestPeerTypeBroadcastInfo(Object):
"""Contains information about a broadcast peer type.
Parameters:
is_creator (``bool``):
If True, returns the list of chats where this user is a broadcast creator.
has_username (``bool``):
If True, returns the list of chats where chat has username.
"""
def __init__(
self, *,
is_creator: bool = None,
has_username: bool = None,
):
super().__init__()
self.is_creator = is_creator
self.has_username = has_username

View File

@ -0,0 +1,52 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from ..object import Object
class RequestPeerTypeChatInfo(Object):
"""Contains information about a chat peer type.
Parameters:
is_creator (``bool``):
If True, returns the list of chats where this user is a chat creator.
is_bot_participant (``bool``):
If True, returns the list of chats where this bot is participant.
has_username (``bool``):
If True, returns the list of chats where chat has username.
has_forum (``bool``):
If True, returns the list of chats where forum topcis is enabled.
"""
def __init__(
self, *,
is_creator: bool = None,
is_bot_participant: bool = None,
has_username: bool = None,
has_forum: bool = None,
):
super().__init__()
self.is_creator = is_creator
self.is_bot_participant = is_bot_participant
self.has_username = has_username
self.has_forum = has_forum

View File

@ -0,0 +1,41 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from ..object import Object
class RequestPeerTypeUserInfo(Object):
"""Contains information about a user peer type.
Parameters:
is_bot (``bool``):
If True, returns the list of users where user is a bot.
is_premium (``bool``):
If True, returns the list of users where user has premium.
"""
def __init__(
self, *,
is_bot: bool = None,
is_premium: bool = None,
):
super().__init__()
self.is_bot = is_bot
self.is_premium = is_premium

View File

@ -0,0 +1,36 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from ..object import Object
class RequestPollInfo(Object):
"""Contains information about a user peer type.
Parameters:
is_quiz (``bool``):
If True, the requested poll will be sent as quiz.
"""
def __init__(
self, *,
is_quiz: bool = None
):
super().__init__()
self.is_quiz = is_quiz