mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-03 08:54:50 +08:00
fix: avoid channel to generate not support reply
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -26,7 +26,7 @@ except Exception as e:
|
||||
|
||||
@singleton
|
||||
class WechatyChannel(ChatChannel):
|
||||
|
||||
NOT_SUPPORT_REPLYTYPE = []
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user