2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Refactor bot keyboard types

This commit is contained in:
Dan 2018-12-17 13:16:05 +01:00
parent 3f643242b1
commit a683e3e917
6 changed files with 26 additions and 44 deletions

View File

@ -16,11 +16,11 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import ReplyKeyboardForceReply
from ..pyrogram_type import PyrogramType
class ForceReply(Object):
class ForceReply(PyrogramType):
"""Upon receiving a message with this object, Telegram clients will display a reply interface to the user
(act as if the user has selected the bot's message and tapped 'Reply').
This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to
@ -33,9 +33,9 @@ class ForceReply(Object):
2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
"""
ID = 0xb0700018
def __init__(self, selective: bool = None):
super().__init__(None, None)
self.selective = selective
@staticmethod

View File

@ -16,15 +16,14 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import (
KeyboardButtonUrl, KeyboardButtonCallback,
KeyboardButtonSwitchInline
)
from ..pyrogram_type import PyrogramType
class InlineKeyboardButton(Object):
class InlineKeyboardButton(PyrogramType):
"""This object represents one button of an inline keyboard. You must use exactly one of the optional fields.
Args:
@ -54,18 +53,10 @@ class InlineKeyboardButton(Object):
# TODO: Add callback_game and pay fields
ID = 0xb0700019
def __init__(self, text: str, callback_data: bytes = None, url: str = None,
switch_inline_query: str = None, switch_inline_query_current_chat: str = None):
super().__init__(None, None)
def __init__(
self,
text: str,
callback_data: bytes = None,
url: str = None,
switch_inline_query: str = None,
switch_inline_query_current_chat: str = None,
# callback_game=None,
# pay: bool = None
):
self.text = text
self.url = url
self.callback_data = callback_data

View File

@ -16,13 +16,12 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import ReplyInlineMarkup, KeyboardButtonRow
from . import InlineKeyboardButton
from ..pyrogram_type import PyrogramType
class InlineKeyboardMarkup(Object):
class InlineKeyboardMarkup(PyrogramType):
"""This object represents an inline keyboard that appears right next to the message it belongs to.
Args:
@ -30,9 +29,9 @@ class InlineKeyboardMarkup(Object):
List of button rows, each represented by a List of InlineKeyboardButton objects.
"""
ID = 0xb0700020
def __init__(self, inline_keyboard: list):
super().__init__(None, None)
self.inline_keyboard = inline_keyboard
@staticmethod

View File

@ -16,13 +16,12 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import KeyboardButton as RawKeyboardButton
from pyrogram.api.types import KeyboardButtonRequestPhone, KeyboardButtonRequestGeoLocation
from ..pyrogram_type import PyrogramType
class KeyboardButton(Object):
class KeyboardButton(PyrogramType):
"""This object represents one button of the reply keyboard.
For simple text buttons String can be used instead of this object to specify text of the button.
Optional fields are mutually exclusive.
@ -41,9 +40,9 @@ class KeyboardButton(Object):
Available in private chats only.
"""
ID = 0xb0700021
def __init__(self, text: str, request_contact: bool = None, request_location: bool = None):
super().__init__(None, None)
self.text = text
self.request_contact = request_contact
self.request_location = request_location

View File

@ -16,15 +16,13 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import KeyboardButtonRow
from pyrogram.api.types import ReplyKeyboardMarkup as RawReplyKeyboardMarkup
from . import KeyboardButton
from ..pyrogram_type import PyrogramType
class ReplyKeyboardMarkup(Object):
class ReplyKeyboardMarkup(PyrogramType):
"""This object represents a custom keyboard with reply options.
Args:
@ -49,15 +47,10 @@ class ReplyKeyboardMarkup(Object):
select the new language. Other users in the group don't see the keyboard.
"""
ID = 0xb0700022
def __init__(self, keyboard: list, resize_keyboard: bool = None, one_time_keyboard: bool = None,
selective: bool = None):
super().__init__(None, None)
def __init__(
self,
keyboard: list,
resize_keyboard: bool = None,
one_time_keyboard: bool = None,
selective: bool = None
):
self.keyboard = keyboard
self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard

View File

@ -16,11 +16,11 @@
# 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 pyrogram.api.core import Object
from pyrogram.api.types import ReplyKeyboardHide
from ..pyrogram_type import PyrogramType
class ReplyKeyboardRemove(Object):
class ReplyKeyboardRemove(PyrogramType):
"""Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and
display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent
by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a
@ -35,9 +35,9 @@ class ReplyKeyboardRemove(Object):
keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
"""
ID = 0xb0700023
def __init__(self, selective: bool = None):
super().__init__(None, None)
self.selective = selective
@staticmethod