Esempio n. 1
0
    async def message_file(self, message_id: str) -> FileBox:
        """
        extract file from message
        :param message_id:
        :return:
        """
        file_chunk_data: List[bytes] = []
        name: str = ''

        async for stream in self.puppet_stub.message_file_stream(id=message_id):
            file_chunk_data.append(stream.file_box_chunk.data)
            if not name and stream.file_box_chunk.name:
                name = stream.file_box_chunk.name

        file_stream = reduce(lambda pre, cu: pre + cu, file_chunk_data)
        file_box = FileBox.from_stream(file_stream, name=name)
        return file_box
Esempio n. 2
0
    async def message_image(self, message_id: str, image_type: ImageType = 3
                            ) -> FileBox:
        """
        get message image data
        :param message_id:
        :param image_type:
        :return:
        """
        file_chunk_data: List[bytes] = []
        name: str = ''

        async for stream in self.puppet_stub.message_image_stream(id=message_id, type=image_type):
            file_chunk_data.append(stream.file_box_chunk.data)
            if not name and stream.file_box_chunk.name:
                name = stream.file_box_chunk.name

        file_stream = reduce(lambda pre, cu: pre + cu, file_chunk_data)
        file_box = FileBox.from_stream(file_stream, name=name)
        return file_box