From 1657e43904ed11fce03c935a7d8b81ab927ecacb Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 13 Apr 2016 20:38:45 -0300 Subject: [PATCH] Adding InlineKeyboardMarkup #232 --- telegram/inlinekeyboardbutton.py | 12 +++++++++++ telegram/inlinekeyboardmarkup.py | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/telegram/inlinekeyboardbutton.py b/telegram/inlinekeyboardbutton.py index 985f52c16..42e4888e3 100644 --- a/telegram/inlinekeyboardbutton.py +++ b/telegram/inlinekeyboardbutton.py @@ -45,3 +45,15 @@ class InlineKeyboardButton(TelegramObject): return None return InlineKeyboardButton(**data) + + @staticmethod + def de_list(data): + if not data: + return [] + + inline_keyboard = list() + for inline_keyboard in data: + inline_keyboard.append(InlineKeyboardButton. + de_json(inline_keyboard)) + + return inline_keyboard diff --git a/telegram/inlinekeyboardmarkup.py b/telegram/inlinekeyboardmarkup.py index 3d29ea07b..b65176c42 100644 --- a/telegram/inlinekeyboardmarkup.py +++ b/telegram/inlinekeyboardmarkup.py @@ -16,3 +16,38 @@ # # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. + +"""This module contains a object that represents a Telegram +InlineKeyboardMarkup""" + +from telegram import ReplyMarkup, InlineKeyboardButton + + +class InlineKeyboardMarkup(ReplyMarkup): + """This object represents a Telegram InlineKeyboardMarkup.""" + + def __init__(self, + inline_keyboard): + # Required + self.inline_keyboard = inline_keyboard + + @staticmethod + def de_json(data): + if not data: + return None + + data['inline_keyboard'] = \ + [InlineKeyboardButton.de_list(inline_keyboard) for inline_keyboard + in data['inline_keyboard']] + + return InlineKeyboardMarkup(**data) + + def to_dict(self): + data = super(InlineKeyboardMarkup, self).to_dict() + + data['inline_keyboard'] = [] + for inline_keyboard in self.inline_keyboard: + data['inline_keyboard'].append( + [x.to_dict() for x in inline_keyboard]) + + return data