예제 #1
0
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(Game, cls).de_json(data, bot)

        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)

        return cls(**data)
예제 #2
0
    def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> Optional['Game']:
        data = cls.parse_data(data)

        if not data:
            return None

        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)

        return cls(**data)
예제 #3
0
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(Game, cls).de_json(data, bot)

        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)

        return cls(**data)
예제 #4
0
 def test_de_json(self, bot, thumb):
     json_dict = {
         'file_id': self.animation_file_id,
         'thumb': thumb.to_dict(),
         'file_name': self.file_name,
         'mime_type': self.mime_type,
         'file_size': self.file_size
     }
     animation = Animation.de_json(json_dict, bot)
     assert animation.file_id == self.animation_file_id
     assert animation.thumb == thumb
     assert animation.file_name == self.file_name
     assert animation.mime_type == self.mime_type
     assert animation.file_size == self.file_size
예제 #5
0
 def test_de_json(self, bot, animation):
     json_dict = {
         'file_id': self.animation_file_id,
         'width': self.width,
         'height': self.height,
         'duration': self.duration,
         'thumb': animation.thumb.to_dict(),
         'file_name': self.file_name,
         'mime_type': self.mime_type,
         'file_size': self.file_size
     }
     animation = Animation.de_json(json_dict, bot)
     assert animation.file_id == self.animation_file_id
     assert animation.thumb == animation.thumb
     assert animation.file_name == self.file_name
     assert animation.mime_type == self.mime_type
     assert animation.file_size == self.file_size
예제 #6
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.Game:

        """
        if not data:
            return None

        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)

        return Game(**data)
 def test_de_json(self, bot, animation):
     json_dict = {
         "file_id": self.animation_file_id,
         "file_unique_id": self.animation_file_unique_id,
         "width": self.width,
         "height": self.height,
         "duration": self.duration,
         "thumb": animation.thumb.to_dict(),
         "file_name": self.file_name,
         "mime_type": self.mime_type,
         "file_size": self.file_size,
     }
     animation = Animation.de_json(json_dict, bot)
     assert animation.file_id == self.animation_file_id
     assert animation.file_unique_id == self.animation_file_unique_id
     assert animation.file_name == self.file_name
     assert animation.mime_type == self.mime_type
     assert animation.file_size == self.file_size
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.Game:

        """
        if not data:
            return None

        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)

        return Game(**data)
예제 #9
0
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(Message, cls).de_json(data, bot)

        data['from_user'] = User.de_json(data.get('from'), bot)
        data['date'] = from_timestamp(data['date'])
        data['chat'] = Chat.de_json(data.get('chat'), bot)
        data['entities'] = MessageEntity.de_list(data.get('entities'), bot)
        data['caption_entities'] = MessageEntity.de_list(data.get('caption_entities'), bot)
        data['forward_from'] = User.de_json(data.get('forward_from'), bot)
        data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'), bot)
        data['forward_date'] = from_timestamp(data.get('forward_date'))
        data['reply_to_message'] = Message.de_json(data.get('reply_to_message'), bot)
        data['edit_date'] = from_timestamp(data.get('edit_date'))
        data['audio'] = Audio.de_json(data.get('audio'), bot)
        data['document'] = Document.de_json(data.get('document'), bot)
        data['animation'] = Animation.de_json(data.get('animation'), bot)
        data['game'] = Game.de_json(data.get('game'), bot)
        data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
        data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
        data['video'] = Video.de_json(data.get('video'), bot)
        data['voice'] = Voice.de_json(data.get('voice'), bot)
        data['video_note'] = VideoNote.de_json(data.get('video_note'), bot)
        data['contact'] = Contact.de_json(data.get('contact'), bot)
        data['location'] = Location.de_json(data.get('location'), bot)
        data['venue'] = Venue.de_json(data.get('venue'), bot)
        data['new_chat_members'] = User.de_list(data.get('new_chat_members'), bot)
        data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
        data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
        data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
        data['invoice'] = Invoice.de_json(data.get('invoice'), bot)
        data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot)
        data['passport_data'] = PassportData.de_json(data.get('passport_data'), bot)

        return cls(bot=bot, **data)