mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add MenuButton related classes
This commit is contained in:
parent
7654dc82e8
commit
76546b0a13
@ -419,6 +419,10 @@ def pyrogram_api():
|
||||
GameHighScore
|
||||
CallbackGame
|
||||
WebAppInfo
|
||||
MenuButton
|
||||
MenuButtonCommands
|
||||
MenuButtonWebApp
|
||||
MenuButtonDefault
|
||||
""",
|
||||
bot_commands="""
|
||||
Bot commands
|
||||
|
@ -33,6 +33,10 @@ from .inline_keyboard_button import InlineKeyboardButton
|
||||
from .inline_keyboard_markup import InlineKeyboardMarkup
|
||||
from .keyboard_button import KeyboardButton
|
||||
from .login_url import LoginUrl
|
||||
from .menu_button import MenuButton
|
||||
from .menu_button_commands import MenuButtonCommands
|
||||
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 .web_app_info import WebAppInfo
|
||||
@ -57,5 +61,9 @@ __all__ = [
|
||||
"BotCommandScopeChatAdministrators",
|
||||
"BotCommandScopeChatMember",
|
||||
"BotCommandScopeDefault",
|
||||
"WebAppInfo"
|
||||
"WebAppInfo",
|
||||
"MenuButton",
|
||||
"MenuButtonCommands",
|
||||
"MenuButtonWebApp",
|
||||
"MenuButtonDefault"
|
||||
]
|
||||
|
44
pyrogram/types/bots_and_keyboards/menu_button.py
Normal file
44
pyrogram/types/bots_and_keyboards/menu_button.py
Normal file
@ -0,0 +1,44 @@
|
||||
# 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/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class MenuButton(Object):
|
||||
"""Describes the bot's menu button in a private chat.
|
||||
|
||||
It should be one of:
|
||||
|
||||
- :obj:`~pyrogram.types.MenuButtonCommands`
|
||||
- :obj:`~pyrogram.types.MenuButtonWebApp`
|
||||
- :obj:`~pyrogram.types.MenuButtonDefault`
|
||||
|
||||
If a menu button other than :obj:`~pyrogram.types.MenuButtonDefault` is set for a private chat, then it is applied
|
||||
in the chat. Otherwise the default menu button is applied. By default, the menu button opens the list of bot
|
||||
commands.
|
||||
"""
|
||||
|
||||
def __init__(self, type: str):
|
||||
super().__init__()
|
||||
|
||||
self.type = type
|
||||
|
||||
async def write(self, client: "pyrogram.Client") -> "raw.base.BotMenuButton":
|
||||
raise NotImplementedError
|
32
pyrogram/types/bots_and_keyboards/menu_button_commands.py
Normal file
32
pyrogram/types/bots_and_keyboards/menu_button_commands.py
Normal file
@ -0,0 +1,32 @@
|
||||
# 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/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from .menu_button import MenuButton
|
||||
|
||||
|
||||
class MenuButtonCommands(MenuButton):
|
||||
"""A menu button, which opens the bot's list of commands.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("commands")
|
||||
|
||||
async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonCommands":
|
||||
return raw.types.BotMenuButtonCommands()
|
32
pyrogram/types/bots_and_keyboards/menu_button_default.py
Normal file
32
pyrogram/types/bots_and_keyboards/menu_button_default.py
Normal file
@ -0,0 +1,32 @@
|
||||
# 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/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
from .menu_button import MenuButton
|
||||
|
||||
|
||||
class MenuButtonDefault(MenuButton):
|
||||
"""Describes that no specific value for the menu button was set.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("default")
|
||||
|
||||
async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonDefault":
|
||||
return raw.types.BotMenuButtonDefault()
|
51
pyrogram/types/bots_and_keyboards/menu_button_web_app.py
Normal file
51
pyrogram/types/bots_and_keyboards/menu_button_web_app.py
Normal file
@ -0,0 +1,51 @@
|
||||
# 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/>.
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types
|
||||
from .menu_button import MenuButton
|
||||
|
||||
|
||||
class MenuButtonWebApp(MenuButton):
|
||||
"""A menu button, which launches a `Web App <https://core.telegram.org/bots/webapps>`_.
|
||||
|
||||
Parameters:
|
||||
text (``str``):
|
||||
Text on the button
|
||||
|
||||
web_app (:obj:`~pyrogram.types.WebAppInfo`):
|
||||
Description of the Web App that will be launched when the user presses the button.
|
||||
The Web App will be able to send an arbitrary message on behalf of the user using the method
|
||||
:meth:`~pyrogram.Client.answer_web_app_query`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
web_app: "types.WebAppInfo"
|
||||
):
|
||||
super().__init__("web_app")
|
||||
|
||||
self.text = text
|
||||
self.web_app = web_app
|
||||
|
||||
async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButton":
|
||||
return raw.types.BotMenuButton(
|
||||
text=self.text,
|
||||
url=self.web_app.url
|
||||
)
|
Loading…
Reference in New Issue
Block a user