Add types: Audio, Document, PhotoSize, Sticker, Video, VideoNote, CallbackQuery, Contact, File, Location, UserProfilePhotos, Venue, Voice

This commit is contained in:
Alex Root Junior 2017-05-26 03:27:22 +03:00
parent bff535ddab
commit a315d6d390
13 changed files with 312 additions and 0 deletions

27
aiogram/types/audio.py Normal file
View file

@ -0,0 +1,27 @@
from . import Deserializable
class Audio(Deserializable):
__slots__ = ('data', 'file_id', 'duration', 'performer', 'title', 'mime_type', 'file_size')
def __init__(self, data, file_id, duration, performer, title, mime_type, file_size):
self.data = data
self.file_id = file_id
self.duration = duration
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
duration = data.get('duration')
performer = data.get('performer')
title = data.get('title')
mime_type = data.get('mime_type')
file_size = data.get('file_size')
return Audio(data, file_id, duration, performer, title, mime_type, file_size)

View file

@ -0,0 +1,29 @@
from . import Deserializable
class CallbackQuery(Deserializable):
__slots__ = ('data', 'id', 'from', 'message', 'inline_message_id', 'chat_instance', 'data', 'game_short_name')
def __init__(self, data, id, from_user, message, inline_message_id, chat_instance, data, game_short_name):
self.data = data
self.id = id
self.from_user = from_user
self.message = message
self.inline_message_id = inline_message_id
self.chat_instance = chat_instance
self.data = data
self.game_short_name = game_short_name
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
id = data.get('id')
from_user = data.get('from')
message = data.get('message')
inline_message_id = data.get('inline_message_id')
chat_instance = data.get('chat_instance')
data = data.get('data')
game_short_name = data.get('game_short_name')
return CallbackQuery(data, id, from_user, message, inline_message_id, chat_instance, data, game_short_name)

23
aiogram/types/contact.py Normal file
View file

@ -0,0 +1,23 @@
from . import Deserializable
class Contact(Deserializable):
__slots__ = ('data', 'phone_number', 'first_name', 'last_name', 'user_id')
def __init__(self, data, phone_number, first_name, last_name, user_id):
self.data = data
self.phone_number = phone_number
self.first_name = first_name
self.last_name = last_name
self.user_id = user_id
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
phone_number = data.get('phone_number')
first_name = data.get('first_name')
last_name = data.get('last_name')
user_id = data.get('user_id')
return Contact(data, phone_number, first_name, last_name, user_id)

25
aiogram/types/document.py Normal file
View file

@ -0,0 +1,25 @@
from . import Deserializable
class Document(Deserializable):
__slots__ = ('data', 'file_id', 'thumb', 'file_name', 'mime_type', 'file_size')
def __init__(self, data, file_id, thumb, file_name, mime_type, file_size):
self.data = data
self.file_id = file_id
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
thumb = data.get('thumb')
file_name = data.get('file_name')
mime_type = data.get('mime_type')
file_size = data.get('file_size')
return Document(data, file_id, thumb, file_name, mime_type, file_size)

21
aiogram/types/file.py Normal file
View file

@ -0,0 +1,21 @@
from . import Deserializable
class File(Deserializable):
__slots__ = ('data', 'file_id', 'file_size', 'file_path')
def __init__(self, data, file_id, file_size, file_path):
self.data = data
self.file_id = file_id
self.file_size = file_size
self.file_path = file_path
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
file_size = data.get('file_size')
file_path = data.get('file_path')
return File(data, file_id, file_size, file_path)

19
aiogram/types/location.py Normal file
View file

@ -0,0 +1,19 @@
from . import Deserializable
class Location(Deserializable):
__slots__ = ('data', 'longitude', 'latitude')
def __init__(self, data, longitude, latitude):
self.data = data
self.longitude = longitude
self.latitude = latitude
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
longitude = data.get('longitude')
latitude = data.get('latitude')
return Location(data, longitude, latitude)

View file

@ -0,0 +1,22 @@
from . import Deserializable
class PhotoSize(Deserializable):
__slots__ = ('file_id', 'width', 'height', 'file_size')
def __init__(self, file_id, width, height, file_size):
self.file_id = file_id
self.width = width
self.height = height
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
width = data.get('width')
height = data.get('height')
file_size = data.get('file_size')
return PhotoSize(file_id, width, height, file_size)

27
aiogram/types/sticker.py Normal file
View file

@ -0,0 +1,27 @@
from . import Deserializable
class Sticker(Deserializable):
__slots__ = ('data', 'file_id', 'width', 'height', 'thumb', 'emoji', 'file_size')
def __init__(self, data, file_id, width, height, thumb, emoji, file_size):
self.data = data
self.file_id = file_id
self.width = width
self.height = height
self.thumb = thumb
self.emoji = emoji
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
width = data.get('width')
height = data.get('height')
thumb = data.get('thumb')
emoji = data.get('emoji')
file_size = data.get('file_size')
return Sticker(data, file_id, width, height, thumb, emoji, file_size)

View file

@ -0,0 +1,19 @@
from . import Deserializable
class UserProfilePhotos(Deserializable):
__slots__ = ('data', 'total_count', 'photos')
def __init__(self, data, total_count, photos):
self.data = data
self.total_count = total_count
self.photos = photos
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
total_count = data.get('total_count')
photos = data.get('photos')
return UserProfilePhotos(data, total_count, photos)

23
aiogram/types/venue.py Normal file
View file

@ -0,0 +1,23 @@
from . import Deserializable
class Venue(Deserializable):
__slots__ = ('data', 'location', 'title', 'address', 'foursquare_id')
def __init__(self, data, location, title, address, foursquare_id):
self.data = data
self.location = location
self.title = title
self.address = address
self.foursquare_id = foursquare_id
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
location = data.get('location')
title = data.get('title')
address = data.get('address')
foursquare_id = data.get('foursquare_id')
return Venue(data, location, title, address, foursquare_id)

29
aiogram/types/video.py Normal file
View file

@ -0,0 +1,29 @@
from . import Deserializable
class Video(Deserializable):
__slots__ = ('data', 'file_id', 'width', 'height', 'duration', 'thumb', 'mime_type', 'file_size')
def __init__(self, data, file_id, width, height, duration, thumb, mime_type, file_size):
self.data = data
self.file_id = file_id
self.width = width
self.height = height
self.duration = duration
self.thumb = thumb
self.mime_type = mime_type
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
width = data.get('width')
height = data.get('height')
duration = data.get('duration')
thumb = data.get('thumb')
mime_type = data.get('mime_type')
file_size = data.get('file_size')
return Video(data, file_id, width, height, duration, thumb, mime_type, file_size)

View file

@ -0,0 +1,25 @@
from . import Deserializable
class VideoNote(Deserializable):
__slots__ = ('data', 'file_id', 'length', 'duration', 'thumb', 'file_size')
def __init__(self, data, file_id, length, duration, thumb, file_size):
self.data = data
self.file_id = file_id
self.length = length
self.duration = duration
self.thumb = thumb
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
length = data.get('length')
duration = data.get('duration')
thumb = data.get('thumb')
file_size = data.get('file_size')
return VideoNote(data, file_id, length, duration, thumb, file_size)

23
aiogram/types/voice.py Normal file
View file

@ -0,0 +1,23 @@
from . import Deserializable
class Voice(Deserializable):
__slots__ = ('data', 'file_id', 'duration', 'mime_type', 'file_size')
def __init__(self, data, file_id, duration, mime_type, file_size):
self.data = data
self.file_id = file_id
self.duration = duration
self.mime_type = mime_type
self.file_size = file_size
@classmethod
def de_json(cls, data):
data = cls.check_json(data)
file_id = data.get('file_id')
duration = data.get('duration')
mime_type = data.get('mime_type')
file_size = data.get('file_size')
return Voice(data, file_id, duration, mime_type, file_size)