Update to Bot API 3.1

This commit is contained in:
Alex Root Junior 2017-07-11 23:08:20 +03:00
parent 1413baf4b8
commit 4e093680c4
7 changed files with 285 additions and 10 deletions

View file

@ -3,6 +3,7 @@ from .audio import Audio
from .callback_query import CallbackQuery
from .chat import Chat, ChatType, ChatActions
from .chat_member import ChatMember, ChatMemberStatus
from .chat_photo import ChatPhoto
from .chosen_inline_result import ChosenInlineResult
from .contact import Contact
from .document import Document
@ -52,6 +53,7 @@ __all__ = [
'ChatActions',
'ChatMember',
'ChatMemberStatus',
'ChatPhoto',
'ChatType',
'ChosenInlineResult',
'Contact',

View file

@ -1,3 +1,4 @@
from . import ChatPhoto
from .base import Deserializable
@ -8,7 +9,8 @@ class Chat(Deserializable):
https://core.telegram.org/bots/api#chat
"""
def __init__(self, id, type, title, username, first_name, last_name, all_members_are_administrators):
def __init__(self, id, type, title, username, first_name, last_name, all_members_are_administrators, photo,
description, invite_link):
self.id: int = id
self.type: str = type
self.title: str = title
@ -16,6 +18,9 @@ class Chat(Deserializable):
self.first_name: str = first_name
self.last_name: str = last_name
self.all_members_are_administrators: bool = all_members_are_administrators
self.photo: ChatPhoto = photo
self.description: str = description
self.invite_link: str = invite_link
@classmethod
def de_json(cls, raw_data) -> 'Chat':
@ -28,8 +33,12 @@ class Chat(Deserializable):
first_name: str = raw_data.get('first_name')
last_name: str = raw_data.get('last_name')
all_members_are_administrators: bool = raw_data.get('all_members_are_administrators', False)
photo = raw_data.get('photo')
description = raw_data.get('description')
invite_link = raw_data.get('invite_link')
return Chat(id, type, title, username, first_name, last_name, all_members_are_administrators)
return Chat(id, type, title, username, first_name, last_name, all_members_are_administrators, photo,
description, invite_link)
@property
def full_name(self):

View file

@ -1,3 +1,5 @@
import datetime
from .base import Deserializable
from .user import User
@ -8,10 +10,34 @@ class ChatMember(Deserializable):
https://core.telegram.org/bots/api#chatmember
"""
def __init__(self, user, status):
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages,
can_edit_messages, can_delete_messages, can_invite_users, can_restrict_members,
can_pin_messages, can_promote_members, can_send_messages, can_send_media_messages,
can_send_other_messages, can_add_web_page_previews
):
self.user: User = user
self.status: str = status
self.until_date: datetime.datetime = until_date
self.can_be_edited: bool = can_be_edited
self.can_change_info: bool = can_change_info
self.can_post_messages: bool = can_post_messages
self.can_edit_messages: bool = can_edit_messages
self.can_delete_messages: bool = can_delete_messages
self.can_invite_users: bool = can_invite_users
self.can_restrict_members: bool = can_restrict_members
self.can_pin_messages: bool = can_pin_messages
self.can_promote_members: bool = can_promote_members
self.can_send_messages: bool = can_send_messages
self.can_send_media_messages: bool = can_send_media_messages
self.can_send_other_messages: bool = can_send_other_messages
self.can_add_web_page_previews: bool = can_add_web_page_previews
@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)
@ -19,7 +45,26 @@ class ChatMember(Deserializable):
user = User.deserialize(raw_data.get('user'))
status = raw_data.get('status')
return ChatMember(user, status)
until_date = cls._parse_date(raw_data.get('until_date'))
can_be_edited = raw_data.get('can_be_edited')
can_change_info = raw_data.get('can_change_info')
can_post_messages = raw_data.get('can_post_messages')
can_edit_messages = raw_data.get('can_edit_messages')
can_delete_messages = raw_data.get('can_delete_messages')
can_invite_users = raw_data.get('can_invite_users')
can_restrict_members = raw_data.get('can_restrict_members')
can_pin_messages = raw_data.get('can_pin_messages')
can_promote_members = raw_data.get('can_promote_members')
can_send_messages = raw_data.get('can_send_messages')
can_send_media_messages = raw_data.get('can_send_media_messages')
can_send_other_messages = raw_data.get('can_send_other_messages')
can_add_web_page_previews = raw_data.get('can_add_web_page_previews')
return ChatMember(user, status, until_date, can_be_edited, can_change_info, can_post_messages,
can_edit_messages, can_delete_messages, can_invite_users, can_restrict_members,
can_pin_messages, can_promote_members, can_send_messages, can_send_media_messages,
can_send_other_messages, can_add_web_page_previews
)
class ChatMemberStatus:

View file

@ -0,0 +1,22 @@
from .base import Deserializable
class ChatPhoto(Deserializable):
"""
This object represents a chat photo.
https://core.telegram.org/bots/api#chatphoto
"""
def __init__(self, small_file_id, big_file_id):
self.small_file_id: str = small_file_id
self.big_file_id: str = big_file_id
@classmethod
def de_json(cls, raw_data):
raw_data = cls.check_json(raw_data)
small_file_id = raw_data.get('small_file_id')
big_file_id = raw_data.get('big_file_id')
return ChatPhoto(small_file_id, big_file_id)