diff --git a/channel/channel.py b/channel/channel.py index 8aae3a6..01e20d6 100644 --- a/channel/channel.py +++ b/channel/channel.py @@ -4,9 +4,10 @@ Message sending channel abstract class from bridge.bridge import Bridge from bridge.context import Context -from bridge.reply import Reply +from bridge.reply import * class Channel(object): + NOT_SUPPORT_REPLYTYPE = [ReplyType.VOICE, ReplyType.IMAGE] def startup(self): """ init channel diff --git a/channel/chat_channel.py b/channel/chat_channel.py index fcf922f..5f3f135 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -112,10 +112,10 @@ class ChatChannel(Channel): else: context.type = ContextType.TEXT context.content = content - if 'desire_rtype' not in context and conf().get('always_reply_voice'): + if 'desire_rtype' not in context and conf().get('always_reply_voice') and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE: context['desire_rtype'] = ReplyType.VOICE elif context.type == ContextType.VOICE: - if 'desire_rtype' not in context and conf().get('voice_reply_voice'): + if 'desire_rtype' not in context and conf().get('voice_reply_voice') and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE: context['desire_rtype'] = ReplyType.VOICE return context @@ -182,19 +182,25 @@ class ChatChannel(Channel): reply = e_context['reply'] desire_rtype = context.get('desire_rtype') if not e_context.is_pass() and reply and reply.type: + + if reply.type in self.NOT_SUPPORT_REPLYTYPE: + logger.error("[WX]reply type not support: " + str(reply.type)) + reply.type = ReplyType.ERROR + reply.content = "不支持发送的消息类型: " + str(reply.type) + if reply.type == ReplyType.TEXT: reply_text = reply.content - if desire_rtype == ReplyType.VOICE: + if desire_rtype == ReplyType.VOICE and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE: reply = super().build_text_to_voice(reply.content) return self._decorate_reply(context, reply) if context['isgroup']: reply_text = '@' + context['msg'].actual_user_nickname + ' ' + reply_text.strip() - reply_text = conf().get("group_chat_reply_prefix", "")+reply_text + reply_text = conf().get("group_chat_reply_prefix", "") + reply_text else: - reply_text = conf().get("single_chat_reply_prefix", "")+reply_text + reply_text = conf().get("single_chat_reply_prefix", "") + reply_text reply.content = reply_text elif reply.type == ReplyType.ERROR or reply.type == ReplyType.INFO: - reply.content = str(reply.type)+":\n" + reply.content + reply.content = "["+str(reply.type)+"]\n" + reply.content elif reply.type == ReplyType.IMAGE_URL or reply.type == ReplyType.VOICE or reply.type == ReplyType.IMAGE: pass else: diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index c70e056..75aa316 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -92,6 +92,7 @@ def qrCallback(uuid,status,qrcode): @singleton class WechatChannel(ChatChannel): + NOT_SUPPORT_REPLYTYPE = [] def __init__(self): super().__init__() self.receivedMsgs = ExpiredDict(60*60*24) diff --git a/channel/wechat/wechaty_channel.py b/channel/wechat/wechaty_channel.py index 6478202..65348ba 100644 --- a/channel/wechat/wechaty_channel.py +++ b/channel/wechat/wechaty_channel.py @@ -26,7 +26,7 @@ except Exception as e: @singleton class WechatyChannel(ChatChannel): - + NOT_SUPPORT_REPLYTYPE = [] def __init__(self): super().__init__() diff --git a/channel/wechatmp/wechatmp_channel.py b/channel/wechatmp/wechatmp_channel.py index fbc0c75..657d54c 100644 --- a/channel/wechatmp/wechatmp_channel.py +++ b/channel/wechatmp/wechatmp_channel.py @@ -28,6 +28,7 @@ import traceback @singleton class WechatMPChannel(ChatChannel): + NOT_SUPPORT_REPLYTYPE = [ReplyType.IMAGE, ReplyType.VOICE] def __init__(self): super().__init__() self.cache_dict = dict() diff --git a/plugins/sdwebui/sdwebui.py b/plugins/sdwebui/sdwebui.py index 227f08e..88d66f4 100644 --- a/plugins/sdwebui/sdwebui.py +++ b/plugins/sdwebui/sdwebui.py @@ -40,6 +40,9 @@ class SDWebUI(Plugin): if e_context['context'].type != ContextType.IMAGE_CREATE: return + channel = e_context['context'].channel + if ReplyType.IMAGE in channel.NOT_SUPPORT_REPLYTYPE: + return logger.debug("[SD] on_handle_context. content: %s" %e_context['context'].content)