예제 #1
0
파일: Message.py 프로젝트: jacopodl/TbotPy
    def build_from_json(jmessage):
        """

        :param jmessage: A dictionary that contains JSON-parsed object
        :type jmessage: dict
        :rtype: Message
        """
        msgfrom = User.build_from_json(jmessage['from'])
        chat = Chat.build_from_json(jmessage['chat'])
        message = Message(int(jmessage['message_id']), msgfrom, int(jmessage['date']), chat)
        if 'forward_from' in jmessage.keys():
            message.set_forward_from(User.build_from_json(jmessage['forward_from']))
        if 'forward_date' in jmessage.keys():
            message.set_forward_date(int(jmessage['forward_date']))
        if 'reply_to_message' in jmessage.keys():
            message.set_reply_to_message(Message.build_from_json(jmessage['reply_to_message']))
        if 'text' in jmessage.keys():
            message.set_text(jmessage['text'])
        if 'audio' in jmessage.keys():
            message.set_audio(Audio.build_from_json(jmessage['audio']))
        if 'document' in jmessage.keys():
            message.set_document(Document.build_from_json(jmessage['document']))
        if 'photo' in jmessage.keys():
            message.set_photo(Message.__extract_ph_array(jmessage['photo']))
        if 'sticker' in jmessage.keys():
            message.set_sticker(Sticker.build_from_json(jmessage['sticker']))
        if 'video' in jmessage.keys():
            message.set_video(Video.build_from_json(jmessage['video']))
        if 'voice' in jmessage.keys():
            message.set_voice(Voice.build_from_json(jmessage['voice']))
        if 'caption' in jmessage.keys():
            message.set_caption(jmessage['caption'])
        if 'contact' in jmessage.keys():
            message.set_contact(Contact.build_from_json(jmessage['contact']))
        if 'location' in jmessage.keys():
            message.set_location(Location.build_from_json(jmessage['location']))
        if 'new_chat_participant' in jmessage.keys():
            message.set_new_chat_participant(User.build_from_json(jmessage['new_chat_participant']))
        if 'left_chat_participant' in jmessage.keys():
            message.set_left_chat_participant(User.build_from_json(jmessage['left_chat_participant']))
        if 'new_chat_title' in jmessage.keys():
            message.set_new_chat_title(jmessage['new_chat_title'])
        if 'new_chat_photo' in jmessage.keys():
            message.set_new_chat_photo(Message.__extract_ph_array(jmessage['new_chat_photo']))
        if 'delete_chat_photo' in jmessage.keys():
            message.set_delete_chat_photo()
        if 'group_chat_created' in jmessage.keys():
            message.set_group_chat_created()
        return message
예제 #2
0
파일: Tbotpy.py 프로젝트: jacopodl/TbotPy
    def get_me(self):
        """
        A simple method for testing your bot's auth token.
        Requires no parameters.
        Returns basic information about the bot in form of a User object.

        :rtype: User
        """
        query = self.endpoint + "getMe"
        data = TbotPy.__urlopen(query)
        return User.build_from_json(json.loads(data)['result'])