mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 21:57:14 +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.bridge import Bridge
|
||||||
from bridge.context import Context
|
from bridge.context import Context
|
||||||
from bridge.reply import Reply
|
from bridge.reply import *
|
||||||
|
|
||||||
class Channel(object):
|
class Channel(object):
|
||||||
|
NOT_SUPPORT_REPLYTYPE = [ReplyType.VOICE, ReplyType.IMAGE]
|
||||||
def startup(self):
|
def startup(self):
|
||||||
"""
|
"""
|
||||||
init channel
|
init channel
|
||||||
|
|||||||
@@ -112,10 +112,10 @@ class ChatChannel(Channel):
|
|||||||
else:
|
else:
|
||||||
context.type = ContextType.TEXT
|
context.type = ContextType.TEXT
|
||||||
context.content = content
|
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
|
context['desire_rtype'] = ReplyType.VOICE
|
||||||
elif context.type == ContextType.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
|
context['desire_rtype'] = ReplyType.VOICE
|
||||||
|
|
||||||
return context
|
return context
|
||||||
@@ -182,19 +182,25 @@ class ChatChannel(Channel):
|
|||||||
reply = e_context['reply']
|
reply = e_context['reply']
|
||||||
desire_rtype = context.get('desire_rtype')
|
desire_rtype = context.get('desire_rtype')
|
||||||
if not e_context.is_pass() and reply and reply.type:
|
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:
|
if reply.type == ReplyType.TEXT:
|
||||||
reply_text = reply.content
|
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)
|
reply = super().build_text_to_voice(reply.content)
|
||||||
return self._decorate_reply(context, reply)
|
return self._decorate_reply(context, reply)
|
||||||
if context['isgroup']:
|
if context['isgroup']:
|
||||||
reply_text = '@' + context['msg'].actual_user_nickname + ' ' + reply_text.strip()
|
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:
|
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
|
reply.content = reply_text
|
||||||
elif reply.type == ReplyType.ERROR or reply.type == ReplyType.INFO:
|
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:
|
elif reply.type == ReplyType.IMAGE_URL or reply.type == ReplyType.VOICE or reply.type == ReplyType.IMAGE:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ def qrCallback(uuid,status,qrcode):
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class WechatChannel(ChatChannel):
|
class WechatChannel(ChatChannel):
|
||||||
|
NOT_SUPPORT_REPLYTYPE = []
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.receivedMsgs = ExpiredDict(60*60*24)
|
self.receivedMsgs = ExpiredDict(60*60*24)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ except Exception as e:
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class WechatyChannel(ChatChannel):
|
class WechatyChannel(ChatChannel):
|
||||||
|
NOT_SUPPORT_REPLYTYPE = []
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import traceback
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class WechatMPChannel(ChatChannel):
|
class WechatMPChannel(ChatChannel):
|
||||||
|
NOT_SUPPORT_REPLYTYPE = [ReplyType.IMAGE, ReplyType.VOICE]
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.cache_dict = dict()
|
self.cache_dict = dict()
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class SDWebUI(Plugin):
|
|||||||
|
|
||||||
if e_context['context'].type != ContextType.IMAGE_CREATE:
|
if e_context['context'].type != ContextType.IMAGE_CREATE:
|
||||||
return
|
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)
|
logger.debug("[SD] on_handle_context. content: %s" %e_context['context'].content)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user