From a315d6d39050f8e5e2e8f1bd00a6f1637c4077fb Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 26 May 2017 03:27:22 +0300 Subject: [PATCH] Add types: Audio, Document, PhotoSize, Sticker, Video, VideoNote, CallbackQuery, Contact, File, Location, UserProfilePhotos, Venue, Voice --- aiogram/types/audio.py | 27 ++++++++++++++++++++++++++ aiogram/types/callback_query.py | 29 ++++++++++++++++++++++++++++ aiogram/types/contact.py | 23 ++++++++++++++++++++++ aiogram/types/document.py | 25 ++++++++++++++++++++++++ aiogram/types/file.py | 21 ++++++++++++++++++++ aiogram/types/location.py | 19 ++++++++++++++++++ aiogram/types/photo_size.py | 22 +++++++++++++++++++++ aiogram/types/sticker.py | 27 ++++++++++++++++++++++++++ aiogram/types/user_profile_photos.py | 19 ++++++++++++++++++ aiogram/types/venue.py | 23 ++++++++++++++++++++++ aiogram/types/video.py | 29 ++++++++++++++++++++++++++++ aiogram/types/video_note.py | 25 ++++++++++++++++++++++++ aiogram/types/voice.py | 23 ++++++++++++++++++++++ 13 files changed, 312 insertions(+) create mode 100644 aiogram/types/audio.py create mode 100644 aiogram/types/callback_query.py create mode 100644 aiogram/types/contact.py create mode 100644 aiogram/types/document.py create mode 100644 aiogram/types/file.py create mode 100644 aiogram/types/location.py create mode 100644 aiogram/types/photo_size.py create mode 100644 aiogram/types/sticker.py create mode 100644 aiogram/types/user_profile_photos.py create mode 100644 aiogram/types/venue.py create mode 100644 aiogram/types/video.py create mode 100644 aiogram/types/video_note.py create mode 100644 aiogram/types/voice.py diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py new file mode 100644 index 00000000..b5260132 --- /dev/null +++ b/aiogram/types/audio.py @@ -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) diff --git a/aiogram/types/callback_query.py b/aiogram/types/callback_query.py new file mode 100644 index 00000000..c37ebbaf --- /dev/null +++ b/aiogram/types/callback_query.py @@ -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) diff --git a/aiogram/types/contact.py b/aiogram/types/contact.py new file mode 100644 index 00000000..6639f5eb --- /dev/null +++ b/aiogram/types/contact.py @@ -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) diff --git a/aiogram/types/document.py b/aiogram/types/document.py new file mode 100644 index 00000000..807dac3f --- /dev/null +++ b/aiogram/types/document.py @@ -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) diff --git a/aiogram/types/file.py b/aiogram/types/file.py new file mode 100644 index 00000000..8f478b50 --- /dev/null +++ b/aiogram/types/file.py @@ -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) diff --git a/aiogram/types/location.py b/aiogram/types/location.py new file mode 100644 index 00000000..c2cf1e3f --- /dev/null +++ b/aiogram/types/location.py @@ -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) diff --git a/aiogram/types/photo_size.py b/aiogram/types/photo_size.py new file mode 100644 index 00000000..843172fe --- /dev/null +++ b/aiogram/types/photo_size.py @@ -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) diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py new file mode 100644 index 00000000..999d83dc --- /dev/null +++ b/aiogram/types/sticker.py @@ -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) diff --git a/aiogram/types/user_profile_photos.py b/aiogram/types/user_profile_photos.py new file mode 100644 index 00000000..767ca2a5 --- /dev/null +++ b/aiogram/types/user_profile_photos.py @@ -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) diff --git a/aiogram/types/venue.py b/aiogram/types/venue.py new file mode 100644 index 00000000..810d4e1d --- /dev/null +++ b/aiogram/types/venue.py @@ -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) diff --git a/aiogram/types/video.py b/aiogram/types/video.py new file mode 100644 index 00000000..bb05fdb0 --- /dev/null +++ b/aiogram/types/video.py @@ -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) diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py new file mode 100644 index 00000000..f3892d6a --- /dev/null +++ b/aiogram/types/video_note.py @@ -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) diff --git a/aiogram/types/voice.py b/aiogram/types/voice.py new file mode 100644 index 00000000..592391d5 --- /dev/null +++ b/aiogram/types/voice.py @@ -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)