Keyboards models and PEP8

This commit is contained in:
Leandro Toledo 2015-07-08 22:33:13 -03:00
parent b2a4d4f5fc
commit ff0f875b85
4 changed files with 62 additions and 4 deletions

View file

@ -20,10 +20,9 @@ from video import Video
from contact import Contact from contact import Contact
from location import Location from location import Location
from chataction import ChatAction from chataction import ChatAction
# from inputfile import InputFile
from userprofilephotos import UserProfilePhotos from userprofilephotos import UserProfilePhotos
# from replykeyboardmarkup import ReplyKeyboardMarkup from replykeyboardmarkup import ReplyKeyboardMarkup
# from replykeyboardhide import ReplyKeyboardHide from replykeyboardhide import ReplyKeyboardHide
from forcereply import ForceReply from forcereply import ForceReply
from replymarkup import ReplyMarkup from replymarkup import ReplyMarkup
from error import TelegramError from error import TelegramError

View file

@ -6,7 +6,8 @@
import json import json
import requests import requests
from telegram import (User, Message, Update, UserProfilePhotos, TelegramError, ReplyMarkup) from telegram import (User, Message, Update, UserProfilePhotos, TelegramError,
ReplyMarkup)
class Bot(object): class Bot(object):

View file

@ -0,0 +1,24 @@
#!/usr/bin/env python
import json
from replymarkup import ReplyMarkup
class ReplyKeyboardHide(ReplyMarkup):
def __init__(self,
hide_keyboard=True,
selective=None):
self.hide_keyboard = hide_keyboard
self.selective = selective
@staticmethod
def de_json(data):
return ReplyKeyboardHide(hide_keyboard=data.get('hide_keyboard', None),
selective=data.get('selective', None))
def to_json(self):
json_data = {'hide_keyboard': self.hide_keyboard}
if self.selective:
json_data['selective'] = self.selective
return json.dumps(json_data)

View file

@ -0,0 +1,34 @@
#!/usr/bin/env python
import json
from replymarkup import ReplyMarkup
class ReplyKeyboardMarkup(ReplyMarkup):
def __init__(self,
keyboard,
resize_keyboard=None,
one_time_keyboard=None,
selective=None):
self.keyboard = keyboard
self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard
self.selective = selective
@staticmethod
def de_json(data):
return ReplyKeyboardMarkup(keyboard=data.get('keyboard', None),
resize_keyboard=data.get('resize_keyboard', None),
one_time_keyboard=data.get('one_time_keyboard', None),
selective=data.get('selective', None))
def to_json(self):
json_data = {'keyboard': self.keyboard}
if self.resize_keyboard:
json_data['resize_keyboard'] = self.resize_keyboard
if self.one_time_keyboard:
json_data['one_time_keyboard'] = self.one_time_keyboard
if self.selective:
json_data['selective'] = self.selective
return json.dumps(json_data)