MCPcopy Index your code
hub / github.com/wechaty/python-wechaty / to_file_box

Method to_file_box

src/wechaty/user/message.py:610–640  ·  view source on GitHub ↗

Extract the Media File from the Message, and put it into the FileBox. Notes: ``` File MessageType is : { MESSAGE_TYPE_ATTACHMENT, MESSAGE_TYPE_EMOTICON, MESSAGE_TYPE_IMAGE, MESSAGE_TYPE_VIDEO

(self)

Source from the content-addressed store, hash-verified

608 return (datetime.now() - self.date()).seconds // 1000
609
610 async def to_file_box(self) -> FileBox:
611 """
612 Extract the Media File from the Message, and put it into the FileBox.
613
614 Notes:
615 ```
616 File MessageType is : {
617 MESSAGE_TYPE_ATTACHMENT,
618 MESSAGE_TYPE_EMOTICON,
619 MESSAGE_TYPE_IMAGE,
620 MESSAGE_TYPE_VIDEO
621 }
622 ```
623 Examples:
624 >>> msg.to_file_box()
625 Returns:
626 FileBox: file box
627 """
628 log.info('Message to FileBox')
629 if self.type() not in SUPPORTED_MESSAGE_FILE_TYPES:
630 raise WechatyOperationError(
631 f'this type <{self.type().name}> message can"t be converted to '
632 f'FileBox'
633 )
634 msg_type: MessageType = self.type()
635 if msg_type == MessageType.MESSAGE_TYPE_IMAGE:
636 file_box = await self.puppet.message_image(self.message_id)
637 else:
638 file_box = await self.puppet.message_file(self.message_id)
639
640 return file_box
641
642 def to_image(self) -> Image:
643 """

Callers 1

on_messageMethod · 0.80

Calls 4

typeMethod · 0.95
message_imageMethod · 0.80
message_fileMethod · 0.80

Tested by

no test coverage detected