From 5874291b150ea54eec7b1a4f22a2c48a4b215957 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 26 May 2017 08:05:34 +0300 Subject: [PATCH] Add WebHookInfo, GameHighScore --- aiogram/types/game_high_score.py | 19 +++++++++++++++++++ aiogram/types/webhook_info.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 aiogram/types/game_high_score.py create mode 100644 aiogram/types/webhook_info.py diff --git a/aiogram/types/game_high_score.py b/aiogram/types/game_high_score.py new file mode 100644 index 00000000..35e4e834 --- /dev/null +++ b/aiogram/types/game_high_score.py @@ -0,0 +1,19 @@ +from . import Deserializable +from .user import User + + +class GameHighScore(Deserializable): + def __init__(self, position, user, score): + self.position: int = position + self.user: User = user + self.score: int = score + + @classmethod + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) + + position = raw_data.get('position') + user = User.deserialize(raw_data.get('user')) + score = raw_data.get('score') + + return GameHighScore(position, user, score) diff --git a/aiogram/types/webhook_info.py b/aiogram/types/webhook_info.py new file mode 100644 index 00000000..73cde70e --- /dev/null +++ b/aiogram/types/webhook_info.py @@ -0,0 +1,32 @@ +import datetime + +from . import Deserializable + + +class WebhookInfo(Deserializable): + def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates): + self.url: str = url + self.has_custom_certificate: bool = has_custom_certificate + self.pending_update_count: int = pending_update_count + self.last_error_date: int = last_error_date + self.last_error_message: str = last_error_message + self.max_connections: int = max_connections + self.allowed_updates: [str] = allowed_updates + + @classmethod + def _parse_date(cls, unix_time): + return datetime.datetime.fromtimestamp(unix_time) + + @classmethod + def de_json(cls, raw_data): + raw_data = cls.check_json(raw_data) + + url = raw_data.get('url') + has_custom_certificate = raw_data.get('has_custom_certificate') + pending_update_count = raw_data.get('pending_update_count') + last_error_date = cls._parse_date(raw_data.get('last_error_date')) + last_error_message = raw_data.get('last_error_message') + max_connections = raw_data.get('max_connections') + allowed_updates = raw_data.get('allowed_updates') + + return WebhookInfo(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates)