Esempio n. 1
0
 def iot_GroupFileMsg_group(ctx: GroupMsg, chat: Chat) -> List[Message]:
     refine_file = refine_file_group_msg(ctx)
     if refine_file:
         file_id = refine_file.FileID
         file_size = refine_file.FileSize
         file_name = refine_file.FileName
         if file_size > 50 * 1024 * 1024:  # 50M
             content = "[File too large, Please check it on your phone]\n" \
                       f"File name: {file_name}\n" \
                       f"File size: {file_size}\n" \
                       f"File id: {file_id}"
             return [efb_unsupported_wrapper(content)]
         try:
             file_info = IOTFactory.action.getGroupFileURL(
                 ctx.FromGroupId, file_id)
             actual_file = download_file(file_info.get('Url', ''))
         except Exception as e:
             logger.warning(f"Failed to download the file! {e}")
             content = "[File message, Please check it on your phone]"
             return [efb_unsupported_wrapper(content)]
         else:
             return [efb_file_wrapper(actual_file, file_name)]
     else:
         content = "[File Message, Please check it on your phone]"
         return [efb_unsupported_wrapper(content)]
Esempio n. 2
0
 def iot_VideoMsg_friend(ctx: FriendMsg, chat: Chat) -> List[Message]:
     refine_video = refine_video_friend_msg(ctx)
     if refine_video:
         video_raw_url = refine_video.VideoUrl
         video_md5 = refine_video.VideoMd5
         try:
             video_info = IOTFactory.action.getVideoURL(
                 group=0, videoURL=video_raw_url, videoMD5=video_md5)
             video_file = download_file(video_info.get('VideoUrl', ''))
         except Exception as e:
             logger.warning(f"Failed to download the video! {e}")
             content = "[Video Message, Please check it on your phone]"
             return [efb_unsupported_wrapper(content)]
         else:
             return [efb_video_wrapper(video_file)]
     else:
         content = "[Video Message, Please check it on your phone]"
         return [efb_unsupported_wrapper(content)]
Esempio n. 3
0
 def iot_PicMsg_friend(ctx: FriendMsg, chat: Chat) -> List[Message]:
     messages = []
     refine_pics = refine_pic_friend_msg(ctx)
     if refine_pics:
         for pics in refine_pics.FriendPic:
             try:
                 f = download_file(pics.Url)
             except Exception as e:
                 logger.warning(f"Failed to download the image! {e}")
                 continue
             else:
                 messages.append(efb_image_wrapper(f))
         if refine_pics.Content:
             messages.append(efb_text_simple_wrapper(refine_pics.Content))
     else:
         messages.append(
             efb_text_simple_wrapper(
                 "Received invalid message format(image)! Dumping content\n"
                 f"{ctx}. Please report that to the developer."))
     return messages
Esempio n. 4
0
 def iot_VoiceMsg_friend(ctx: FriendMsg, chat: Chat) -> List[Message]:
     if not VOICE_SUPPORTED:
         content = "[Voice Message, Please check it on your phone]"
         return [efb_unsupported_wrapper(content)]
     refine_voices = refine_voice_friend_msg(ctx)
     if refine_voices:
         try:
             input_file = download_file(refine_voices.VoiceUrl)
         except Exception as e:
             logger.warning(f"Failed to download the voice! {e}")
             content = "[Voice Message, Please check it on your phone]"
             return [efb_unsupported_wrapper(content)]
         else:
             output_file = tempfile.NamedTemporaryFile()
             if not Silkv3.decode(input_file.name, output_file.name):
                 content = "[Voice Message, Please check it on your phone]"
                 return [efb_unsupported_wrapper(content)]
             pydub.AudioSegment.from_raw(file=output_file, sample_width=2, frame_rate=24000, channels=1) \
                 .export(output_file, format="ogg", codec="libopus",
                         parameters=['-vbr', 'on'])
             return [efb_voice_wrapper(output_file)]
     else:
         content = "[Voice Message, Please check it on your phone]"
         return [efb_unsupported_wrapper(content)]