Exemplo n.º 1
0
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['Update']:
        """See :meth:`telegram.TelegramObject.de_json`."""
        data = cls._parse_data(data)

        if not data:
            return None

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'),
                                                 bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'),
                                                   bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(
            data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(
            data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(
            data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(
            data.get('edited_channel_post'), bot)
        data['poll'] = Poll.de_json(data.get('poll'), bot)
        data['poll_answer'] = PollAnswer.de_json(data.get('poll_answer'), bot)
        data['my_chat_member'] = ChatMemberUpdated.de_json(
            data.get('my_chat_member'), bot)
        data['chat_member'] = ChatMemberUpdated.de_json(
            data.get('chat_member'), bot)
        data['chat_join_request'] = ChatJoinRequest.de_json(
            data.get('chat_join_request'), bot)

        return cls(**data)
Exemplo n.º 2
0
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['Update']:
        data = cls.parse_data(data)

        if not data:
            return None

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'),
                                                 bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'),
                                                   bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(
            data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(
            data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(
            data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(
            data.get('edited_channel_post'), bot)
        data['poll'] = Poll.de_json(data.get('poll'), bot)
        data['poll_answer'] = PollAnswer.de_json(data.get('poll_answer'), bot)

        return cls(**data)
Exemplo n.º 3
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data = super(Update, Update).de_json(data, bot)

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'),
                                                 bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'),
                                                   bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(
            data.get('callback_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(
            data.get('edited_channel_post'), bot)

        return Update(**data)
Exemplo n.º 4
0
    def de_json(cls, data, bot):
        if not data:
            return None

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

        message = data.get('message')
        if message:
            message['default_quote'] = data.get('default_quote')
        data['message'] = Message.de_json(message, bot)
        edited_message = data.get('edited_message')
        if edited_message:
            edited_message['default_quote'] = data.get('default_quote')
        data['edited_message'] = Message.de_json(edited_message, bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        callback_query = data.get('callback_query')
        if callback_query:
            callback_query['default_quote'] = data.get('default_quote')
        data['callback_query'] = CallbackQuery.de_json(callback_query, bot)
        data['shipping_query'] = ShippingQuery.de_json(data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(data.get('pre_checkout_query'), bot)
        channel_post = data.get('channel_post')
        if channel_post:
            channel_post['default_quote'] = data.get('default_quote')
        data['channel_post'] = Message.de_json(channel_post, bot)
        edited_channel_post = data.get('edited_channel_post')
        if edited_channel_post:
            edited_channel_post['default_quote'] = data.get('default_quote')
        data['edited_channel_post'] = Message.de_json(edited_channel_post, bot)
        data['poll'] = Poll.de_json(data.get('poll'), bot)

        return cls(**data)
Exemplo n.º 5
0
    def de_json(cls, data, bot):
        if not data:
            return None

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

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'),
                                                 bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'),
                                                   bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(
            data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(
            data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(
            data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(
            data.get('edited_channel_post'), bot)
        data['poll'] = Poll.de_json(data.get('poll'), bot)

        return cls(**data)
Exemplo n.º 6
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data = super(Update, Update).de_json(data, bot)

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)

        return Update(**data)
Exemplo n.º 7
0
    def test_de_json(self, bot):
        json_dict = {'id': self.id_,
                     'from': self.from_user.to_dict(),
                     'chat_instance': self.chat_instance,
                     'message': self.message.to_dict(),
                     'data': self.data,
                     'inline_message_id': self.inline_message_id,
                     'game_short_name': self.game_short_name}
        callback_query = CallbackQuery.de_json(json_dict, bot)

        assert callback_query.id == self.id_
        assert callback_query.from_user == self.from_user
        assert callback_query.chat_instance == self.chat_instance
        assert callback_query.message == self.message
        assert callback_query.data == self.data
        assert callback_query.inline_message_id == self.inline_message_id
        assert callback_query.game_short_name == self.game_short_name
    def test_de_json(self, bot):
        json_dict = {'id': self.id,
                     'from': self.from_user.to_dict(),
                     'chat_instance': self.chat_instance,
                     'message': self.message.to_dict(),
                     'data': self.data,
                     'inline_message_id': self.inline_message_id,
                     'game_short_name': self.game_short_name}
        callback_query = CallbackQuery.de_json(json_dict, bot)

        assert callback_query.id == self.id
        assert callback_query.from_user == self.from_user
        assert callback_query.chat_instance == self.chat_instance
        assert callback_query.message == self.message
        assert callback_query.data == self.data
        assert callback_query.inline_message_id == self.inline_message_id
        assert callback_query.game_short_name == self.game_short_name
Exemplo n.º 9
0
    def de_json(data):
        """
        Args:
            data (dict):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data['message'] = Message.de_json(data.get('message'))
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
        data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))

        return Update(**data)
Exemplo n.º 10
0
    def de_json(cls, data, bot):
        if not data:
            return None

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

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)

        return cls(**data)
Exemplo n.º 11
0
    def de_json(data):
        """
        Args:
            data (dict):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data['message'] = Message.de_json(data.get('message'))
        data['edited_message'] = Message.de_json(data.get('edited_message'))
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
        data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))

        return Update(**data)
Exemplo n.º 12
0
    def test_de_json(self, bot):
        json_dict = {
            "id": self.id_,
            "from": self.from_user.to_dict(),
            "chat_instance": self.chat_instance,
            "message": self.message.to_dict(),
            "data": self.data,
            "inline_message_id": self.inline_message_id,
            "game_short_name": self.game_short_name,
        }
        callback_query = CallbackQuery.de_json(json_dict, bot)

        assert callback_query.id == self.id_
        assert callback_query.from_user == self.from_user
        assert callback_query.chat_instance == self.chat_instance
        assert callback_query.message == self.message
        assert callback_query.data == self.data
        assert callback_query.inline_message_id == self.inline_message_id
        assert callback_query.game_short_name == self.game_short_name