mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 06:25:12 +01:00
Fixes #12 and changes to_data to to_dict
This commit is contained in:
parent
859f04e566
commit
f4ad7037e1
16 changed files with 32 additions and 32 deletions
|
@ -22,7 +22,7 @@ class Audio(TelegramObject):
|
|||
mime_type=data.get('mime_type', None),
|
||||
file_size=data.get('file_size', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'duration': self.duration}
|
||||
if self.mime_type:
|
||||
|
|
|
@ -11,7 +11,7 @@ class TelegramObject(object):
|
|||
__metaclass__ = ABCMeta
|
||||
|
||||
def __str__(self):
|
||||
return self.to_data()
|
||||
return str(self.to_dict())
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.__dict__[item]
|
||||
|
@ -21,8 +21,8 @@ class TelegramObject(object):
|
|||
raise NotImplementedError
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_data())
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@abstractmethod
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
return
|
||||
|
|
|
@ -22,7 +22,7 @@ class Contact(TelegramObject):
|
|||
last_name=data.get('last_name', None),
|
||||
user_id=data.get('user_id', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'phone_number': self.phone_number,
|
||||
'first_name': self.first_name}
|
||||
if self.last_name:
|
||||
|
|
|
@ -31,9 +31,9 @@ class Document(TelegramObject):
|
|||
mime_type=data.get('mime_type', None),
|
||||
file_size=data.get('file_size', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'thumb': self.thumb.to_data()}
|
||||
'thumb': self.thumb.to_dict()}
|
||||
if self.file_name:
|
||||
data['file_name'] = self.file_name
|
||||
if self.mime_type:
|
||||
|
|
|
@ -16,7 +16,7 @@ class ForceReply(TelegramObject):
|
|||
return ForceReply(force_reply=data.get('force_reply', None),
|
||||
selective=data.get('selective', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'force_reply': self.force_reply}
|
||||
if self.selective:
|
||||
data['selective'] = self.selective
|
||||
|
|
|
@ -16,7 +16,7 @@ class GroupChat(TelegramObject):
|
|||
return GroupChat(id=data.get('id', None),
|
||||
title=data.get('title', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'id': self.id,
|
||||
'title': self.title}
|
||||
return data
|
||||
|
|
|
@ -16,7 +16,7 @@ class Location(TelegramObject):
|
|||
return Location(longitude=data.get('longitude', None),
|
||||
latitude=data.get('latitude', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'longitude': self.longitude,
|
||||
'latitude': self.latitude}
|
||||
return data
|
||||
|
|
|
@ -163,11 +163,11 @@ class Message(TelegramObject):
|
|||
delete_chat_photo=data.get('delete_chat_photo', None),
|
||||
group_chat_created=data.get('group_chat_created', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'message_id': self.message_id,
|
||||
'from': self.from_user.to_data(),
|
||||
'from': self.from_user.to_dict(),
|
||||
'date': self.date,
|
||||
'chat': self.chat.to_data()}
|
||||
'chat': self.chat.to_dict()}
|
||||
if self.forward_from:
|
||||
data['forward_from'] = self.forward_from
|
||||
if self.forward_date:
|
||||
|
@ -177,19 +177,19 @@ class Message(TelegramObject):
|
|||
if self.text:
|
||||
data['text'] = self.text
|
||||
if self.audio:
|
||||
data['audio'] = self.audio.to_data()
|
||||
data['audio'] = self.audio.to_dict()
|
||||
if self.document:
|
||||
data['document'] = self.document.to_data()
|
||||
data['document'] = self.document.to_dict()
|
||||
if self.photo:
|
||||
data['photo'] = self.photo.to_data()
|
||||
data['photo'] = [p.to_dict() for p in self.photo]
|
||||
if self.sticker:
|
||||
data['sticker'] = self.sticker.to_data()
|
||||
data['sticker'] = self.sticker.to_dict()
|
||||
if self.video:
|
||||
data['video'] = self.video.to_data()
|
||||
data['video'] = self.video.to_dict()
|
||||
if self.contact:
|
||||
data['contact'] = self.contact.to_data()
|
||||
data['contact'] = self.contact.to_dict()
|
||||
if self.location:
|
||||
data['location'] = self.location.to_data()
|
||||
data['location'] = self.location.to_dict()
|
||||
if self.new_chat_participant:
|
||||
data['new_chat_participant'] = self.new_chat_participant
|
||||
if self.left_chat_participant:
|
||||
|
|
|
@ -22,7 +22,7 @@ class PhotoSize(TelegramObject):
|
|||
height=data.get('height', None),
|
||||
file_size=data.get('file_size', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'width': self.width,
|
||||
'height': self.height}
|
||||
|
|
|
@ -16,7 +16,7 @@ class ReplyKeyboardHide(ReplyMarkup):
|
|||
return ReplyKeyboardHide(hide_keyboard=data.get('hide_keyboard', None),
|
||||
selective=data.get('selective', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'hide_keyboard': self.hide_keyboard}
|
||||
if self.selective:
|
||||
data['selective'] = self.selective
|
||||
|
|
|
@ -26,7 +26,7 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
),
|
||||
selective=data.get('selective', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'keyboard': self.keyboard}
|
||||
if self.resize_keyboard:
|
||||
data['resize_keyboard'] = self.resize_keyboard
|
||||
|
|
|
@ -31,11 +31,11 @@ class Sticker(TelegramObject):
|
|||
thumb=thumb,
|
||||
file_size=data.get('file_size', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'width': self.width,
|
||||
'height': self.height,
|
||||
'thumb': self.thumb.to_data()}
|
||||
'thumb': self.thumb.to_dict()}
|
||||
if self.file_size:
|
||||
data['file_size'] = self.file_size
|
||||
return data
|
||||
|
|
|
@ -22,8 +22,8 @@ class Update(TelegramObject):
|
|||
return Update(update_id=data.get('update_id', None),
|
||||
message=message)
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'update_id': self.update_id}
|
||||
if self.message:
|
||||
data['message'] = self.message.to_data()
|
||||
data['message'] = self.message.to_dict()
|
||||
return data
|
||||
|
|
|
@ -30,7 +30,7 @@ class User(TelegramObject):
|
|||
last_name=data.get('last_name', None),
|
||||
username=data.get('username', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'id': self.id,
|
||||
'first_name': self.first_name}
|
||||
if self.last_name:
|
||||
|
|
|
@ -24,12 +24,12 @@ class UserProfilePhotos(TelegramObject):
|
|||
return UserProfilePhotos(total_count=data.get('total_count', None),
|
||||
photos=photos)
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {}
|
||||
if self.total_count:
|
||||
data['total_count'] = self.total_count
|
||||
if self.photos:
|
||||
data['photos'] = []
|
||||
for photo in self.photos:
|
||||
data['photos'].append([x.to_data() for x in photo])
|
||||
data['photos'].append([x.to_dict() for x in photo])
|
||||
return data
|
||||
|
|
|
@ -40,12 +40,12 @@ class Video(TelegramObject):
|
|||
file_size=data.get('file_size', None),
|
||||
caption=data.get('caption', None))
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'file_id': self.file_id,
|
||||
'width': self.width,
|
||||
'height': self.height,
|
||||
'duration': self.duration,
|
||||
'thumb': self.thumb.to_data()}
|
||||
'thumb': self.thumb.to_dict()}
|
||||
if self.mime_type:
|
||||
data['mime_type'] = self.mime_type
|
||||
if self.file_size:
|
||||
|
|
Loading…
Reference in a new issue