@@ -92,6 +92,7 @@ class LinkAIBot(Bot): | |||||
"frequency_penalty": conf().get("frequency_penalty", 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容 | "frequency_penalty": conf().get("frequency_penalty", 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容 | ||||
"presence_penalty": conf().get("presence_penalty", 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容 | "presence_penalty": conf().get("presence_penalty", 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容 | ||||
"session_id": session_id, | "session_id": session_id, | ||||
"sender_id": session_id, | |||||
"channel_type": conf().get("channel_type", "wx") | "channel_type": conf().get("channel_type", "wx") | ||||
} | } | ||||
try: | try: | ||||
@@ -11,7 +11,7 @@ class ReplyType(Enum): | |||||
VIDEO_URL = 5 # 视频URL | VIDEO_URL = 5 # 视频URL | ||||
FILE = 6 # 文件 | FILE = 6 # 文件 | ||||
CARD = 7 # 微信名片,仅支持ntchat | CARD = 7 # 微信名片,仅支持ntchat | ||||
InviteRoom = 8 # 邀请好友进群 | |||||
INVITE_ROOM = 8 # 邀请好友进群 | |||||
INFO = 9 | INFO = 9 | ||||
ERROR = 10 | ERROR = 10 | ||||
TEXT_ = 11 # 强制文本 | TEXT_ = 11 # 强制文本 | ||||
@@ -170,11 +170,13 @@ class ChatChannel(Channel): | |||||
reply = self._generate_reply(context) | reply = self._generate_reply(context) | ||||
logger.debug("[WX] ready to decorate reply: {}".format(reply)) | logger.debug("[WX] ready to decorate reply: {}".format(reply)) | ||||
# reply的包装步骤 | # reply的包装步骤 | ||||
reply = self._decorate_reply(context, reply) | |||||
if reply and reply.content: | |||||
reply = self._decorate_reply(context, reply) | |||||
# reply的发送步骤 | |||||
self._send_reply(context, reply) | |||||
# reply的发送步骤 | |||||
self._send_reply(context, reply) | |||||
def _generate_reply(self, context: Context, reply: Reply = Reply()) -> Reply: | def _generate_reply(self, context: Context, reply: Reply = Reply()) -> Reply: | ||||
e_context = PluginManager().emit_event( | e_context = PluginManager().emit_event( | ||||
@@ -233,7 +233,6 @@ class WechatChannel(ChatChannel): | |||||
logger.info("[WX] sendImage url={}, receiver={}".format(img_url, receiver)) | logger.info("[WX] sendImage url={}, receiver={}".format(img_url, receiver)) | ||||
elif reply.type == ReplyType.IMAGE: # 从文件读取图片 | elif reply.type == ReplyType.IMAGE: # 从文件读取图片 | ||||
image_storage = reply.content | image_storage = reply.content | ||||
image_storage.seek(0) | |||||
itchat.send_image(image_storage, toUserName=receiver) | itchat.send_image(image_storage, toUserName=receiver) | ||||
logger.info("[WX] sendImage, receiver={}".format(receiver)) | logger.info("[WX] sendImage, receiver={}".format(receiver)) | ||||
elif reply.type == ReplyType.FILE: # 新增文件回复类型 | elif reply.type == ReplyType.FILE: # 新增文件回复类型 | ||||
@@ -99,7 +99,7 @@ class PluginManager: | |||||
try: | try: | ||||
self.current_plugin_path = plugin_path | self.current_plugin_path = plugin_path | ||||
if plugin_path in self.loaded: | if plugin_path in self.loaded: | ||||
if self.loaded[plugin_path] == None: | |||||
if plugin_name.upper() != 'GODCMD': | |||||
logger.info("reload module %s" % plugin_name) | logger.info("reload module %s" % plugin_name) | ||||
self.loaded[plugin_path] = importlib.reload(sys.modules[import_path]) | self.loaded[plugin_path] = importlib.reload(sys.modules[import_path]) | ||||
dependent_module_names = [name for name in sys.modules.keys() if name.startswith(import_path + ".")] | dependent_module_names = [name for name in sys.modules.keys() if name.startswith(import_path + ".")] | ||||
@@ -141,19 +141,21 @@ class PluginManager: | |||||
failed_plugins = [] | failed_plugins = [] | ||||
for name, plugincls in self.plugins.items(): | for name, plugincls in self.plugins.items(): | ||||
if plugincls.enabled: | if plugincls.enabled: | ||||
if name not in self.instances: | |||||
try: | |||||
instance = plugincls() | |||||
except Exception as e: | |||||
logger.warn("Failed to init %s, diabled. %s" % (name, e)) | |||||
self.disable_plugin(name) | |||||
failed_plugins.append(name) | |||||
continue | |||||
self.instances[name] = instance | |||||
for event in instance.handlers: | |||||
if event not in self.listening_plugins: | |||||
self.listening_plugins[event] = [] | |||||
self.listening_plugins[event].append(name) | |||||
if 'GODCMD' in self.instances and name == 'GODCMD': | |||||
continue | |||||
# if name not in self.instances: | |||||
try: | |||||
instance = plugincls() | |||||
except Exception as e: | |||||
logger.warn("Failed to init %s, diabled. %s" % (name, e)) | |||||
self.disable_plugin(name) | |||||
failed_plugins.append(name) | |||||
continue | |||||
self.instances[name] = instance | |||||
for event in instance.handlers: | |||||
if event not in self.listening_plugins: | |||||
self.listening_plugins[event] = [] | |||||
self.listening_plugins[event].append(name) | |||||
self.refresh_order() | self.refresh_order() | ||||
return failed_plugins | return failed_plugins | ||||