This commit is contained in:
Leandro Toledo 2015-07-08 21:58:13 -03:00
parent bfe5b79ad9
commit b2a4d4f5fc
9 changed files with 102 additions and 114 deletions

View file

@ -2,16 +2,15 @@
class Contact(object):
def __init__(self, **kwargs):
param_defaults = {
'phone_number': None,
'first_name': None,
'last_name': None,
'user_id': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
phone_number,
first_name,
last_name=None,
user_id=None):
self.phone_number = phone_number
self.first_name = first_name
self.last_name = last_name
self.user_id = user_id
@staticmethod
def de_json(data):

View file

@ -6,14 +6,11 @@ from replymarkup import ReplyMarkup
class ForceReply(ReplyMarkup):
def __init__(self, **kwargs):
param_defaults = {
'force_reply': True,
'selective': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
force_reply=True,
selective=None):
self.force_reply = force_reply
self.selective = selective
@staticmethod
def de_json(data):

View file

@ -2,18 +2,11 @@
class GroupChat(object):
def __init__(self, **kwargs):
param_defaults = {
'id': None,
'title': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
@property
def chat_id(self):
return self.id
def __init__(self,
id,
title):
self.id = id
self.title = title
@staticmethod
def de_json(data):

View file

@ -2,14 +2,11 @@
class Location(object):
def __init__(self, **kwargs):
param_defaults = {
'longitude': None,
'latitude': None,
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
longitude,
latitude):
self.longitude = longitude
self.latitude = latitude
@staticmethod
def de_json(data):

View file

@ -2,33 +2,49 @@
class Message(object):
def __init__(self, **kwargs):
param_defaults = {
'message_id': None,
'user': None,
'date': None,
'chat': None,
'forward_from': None,
'forward_date': None,
'reply_to_message': None,
'text': None,
'audio': None,
'document': None,
'photo': None,
'sticker': None,
'video': None,
'contact': None,
'location': None,
'new_chat_participant': None,
'left_chat_participant': None,
'new_chat_title': None,
'new_chat_photo': None,
'delete_chat_photo': None,
'group_chat_created': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
message_id,
from_user,
date,
chat,
forward_from=None,
forward_date=None,
reply_to_message=None,
text=None,
audio=None,
document=None,
photo=None,
sticker=None,
video=None,
contact=None,
location=None,
new_chat_participant=None,
left_chat_participant=None,
new_chat_title=None,
new_chat_photo=None,
delete_chat_photo=None,
group_chat_created=None):
self.message_id = message_id
self.from_user = from_user
self.date = date
self.chat = chat
self.forward_from = forward_from
self.forward_date = forward_date
self.reply_to_message = reply_to_message
self.text = text
self.audio = audio
self.document = document
self.photo = photo
self.sticker = sticker
self.video = video
self.contact = contact
self.location = location
self.new_chat_participant = new_chat_participant
self.left_chat_participant = left_chat_participant
self.new_chat_title = new_chat_title
self.new_chat_photo = new_chat_photo
self.delete_chat_photo = delete_chat_photo
self.group_chat_created = group_chat_created
@property
def chat_id(self):
@ -36,11 +52,11 @@ class Message(object):
@staticmethod
def de_json(data):
if 'from' in data: # from on api
if 'from' in data: # from is a reserved word, use user_from instead.
from telegram import User
user = User.de_json(data['from'])
from_user = User.de_json(data['from'])
else:
user = None
from_user = None
if 'chat' in data:
if 'username' in data['chat']:
@ -59,9 +75,7 @@ class Message(object):
forward_from = None
if 'reply_to_message' in data:
reply_to_message = Message.de_json(
data['reply_to_message']
)
reply_to_message = Message.de_json(data['reply_to_message'])
else:
reply_to_message = None
@ -109,22 +123,18 @@ class Message(object):
if 'new_chat_participant' in data:
from telegram import User
new_chat_participant = User.de_json(
data['new_chat_participant']
)
new_chat_participant = User.de_json(data['new_chat_participant'])
else:
new_chat_participant = None
if 'left_chat_participant' in data:
from telegram import User
left_chat_participant = User.de_json(
data['left_chat_participant']
)
left_chat_participant = User.de_json(data['left_chat_participant'])
else:
left_chat_participant = None
return Message(message_id=data.get('message_id', None),
user=user,
from_user=from_user,
date=data.get('date', None),
chat=chat,
forward_from=forward_from,

View file

@ -2,16 +2,15 @@
class PhotoSize(object):
def __init__(self, **kwargs):
param_defaults = {
'file_id': None,
'width': None,
'height': None,
'file_size': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
file_id,
width,
height,
file_size=None):
self.file_id = file_id
self.width = width
self.height = height
self.file_size = file_size
@staticmethod
def de_json(data):

View file

@ -2,14 +2,11 @@
class Update(object):
def __init__(self, **kwargs):
param_defaults = {
'update_id': None,
'message': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
update_id,
message=None):
self.update_id = update_id
self.message = message
@staticmethod
def de_json(data):

View file

@ -2,16 +2,15 @@
class User(object):
def __init__(self, **kwargs):
param_defaults = {
'id': None,
'first_name': None,
'last_name': None,
'username': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
id,
first_name,
last_name=None,
username=None):
self.id = id
self.first_name = first_name
self.last_name = last_name
self.username = username
@staticmethod
def de_json(data):

View file

@ -2,14 +2,11 @@
class UserProfilePhotos(object):
def __init__(self, **kwargs):
param_defaults = {
'total_count': None,
'photos': None
}
for (param, default) in param_defaults.iteritems():
setattr(self, param, kwargs.get(param, default))
def __init__(self,
total_count,
photos):
self.total_count = total_count
self.photos = photos
@staticmethod
def de_json(data):