示例#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)]
示例#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)]
示例#3
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)]
示例#4
0
 def fallback(*args, **kwargs):
     content = f"Unsupported Message Type: {name}"
     return [efb_unsupported_wrapper(content)]
示例#5
0
 def iot_XmlMsg_group(ctx: GroupMsg, chat: Chat) -> List[Message]:
     with suppress(Exception):
         ctx.Content = json.loads(ctx.Content)
     content = str(ctx.Content)
     return [efb_unsupported_wrapper(content)]
示例#6
0
 def iot_JsonMsg_friend(ctx: FriendMsg, chat: Chat) -> List[Message]:
     with suppress(Exception):
         ctx.Content = json.loads(ctx.Content)
     content = str(ctx.Content)
     return [efb_unsupported_wrapper(content)]