From a683e3e917dd2f911fdb76ea321b6f07aa38de21 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 17 Dec 2018 13:16:05 +0100 Subject: [PATCH] Refactor bot keyboard types --- pyrogram/client/types/bots/force_reply.py | 8 ++++---- .../types/bots/inline_keyboard_button.py | 19 +++++-------------- .../types/bots/inline_keyboard_markup.py | 9 ++++----- pyrogram/client/types/bots/keyboard_button.py | 9 ++++----- .../types/bots/reply_keyboard_markup.py | 17 +++++------------ .../types/bots/reply_keyboard_remove.py | 8 ++++---- 6 files changed, 26 insertions(+), 44 deletions(-) diff --git a/pyrogram/client/types/bots/force_reply.py b/pyrogram/client/types/bots/force_reply.py index 2d3cc98f..6d91ff5f 100644 --- a/pyrogram/client/types/bots/force_reply.py +++ b/pyrogram/client/types/bots/force_reply.py @@ -16,11 +16,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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 diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index 3d6c7b6b..34718fd1 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -16,15 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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 diff --git a/pyrogram/client/types/bots/inline_keyboard_markup.py b/pyrogram/client/types/bots/inline_keyboard_markup.py index 2a6993c4..bde31ec4 100644 --- a/pyrogram/client/types/bots/inline_keyboard_markup.py +++ b/pyrogram/client/types/bots/inline_keyboard_markup.py @@ -16,13 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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 diff --git a/pyrogram/client/types/bots/keyboard_button.py b/pyrogram/client/types/bots/keyboard_button.py index b9af3b46..0566fc20 100644 --- a/pyrogram/client/types/bots/keyboard_button.py +++ b/pyrogram/client/types/bots/keyboard_button.py @@ -16,13 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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 diff --git a/pyrogram/client/types/bots/reply_keyboard_markup.py b/pyrogram/client/types/bots/reply_keyboard_markup.py index 29fc1081..77b72562 100644 --- a/pyrogram/client/types/bots/reply_keyboard_markup.py +++ b/pyrogram/client/types/bots/reply_keyboard_markup.py @@ -16,15 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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 diff --git a/pyrogram/client/types/bots/reply_keyboard_remove.py b/pyrogram/client/types/bots/reply_keyboard_remove.py index 3e2aebf5..82adb859 100644 --- a/pyrogram/client/types/bots/reply_keyboard_remove.py +++ b/pyrogram/client/types/bots/reply_keyboard_remove.py @@ -16,11 +16,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -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