diff --git a/channel/chat_channel.py b/channel/chat_channel.py index f178130..fcf922f 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -48,7 +48,7 @@ class ChatChannel(Channel): if first_in: # context首次传入时,receiver是None,根据类型设置receiver config = conf() cmsg = context['msg'] - if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', False): + if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', True): logger.debug("[WX]self message skipped") return None if context["isgroup"]: diff --git a/plugins/banwords/banwords.py b/plugins/banwords/banwords.py index ede2779..e2719d6 100644 --- a/plugins/banwords/banwords.py +++ b/plugins/banwords/banwords.py @@ -38,7 +38,8 @@ class Banwords(Plugin): self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context logger.info("[Banwords] inited") except Exception as e: - logger.warn("Banwords init failed: %s, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/banwords ." % e) + logger.warn("[Banwords] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/banwords .") + raise e diff --git a/plugins/bdunit/bdunit.py b/plugins/bdunit/bdunit.py index d7b808c..59302a5 100644 --- a/plugins/bdunit/bdunit.py +++ b/plugins/bdunit/bdunit.py @@ -36,8 +36,8 @@ class BDunit(Plugin): self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context logger.info("[BDunit] inited") except Exception as e: - logger.warn( - "BDunit init failed: %s, ignore " % e) + logger.warn("[BDunit] init failed, ignore ") + raise e def on_handle_context(self, e_context: EventContext): diff --git a/plugins/plugin_manager.py b/plugins/plugin_manager.py index c7d7ddf..c6a6631 100644 --- a/plugins/plugin_manager.py +++ b/plugins/plugin_manager.py @@ -95,7 +95,12 @@ class PluginManager: for name, plugincls in self.plugins.items(): if plugincls.enabled: if name not in self.instances: - instance = plugincls() + try: + instance = plugincls() + except Exception as e: + logger.warn("Failed to create init %s, diabled. %s" % (name, e)) + self.disable_plugin(name) + continue self.instances[name] = instance for event in instance.handlers: if event not in self.listening_plugins: diff --git a/plugins/role/role.py b/plugins/role/role.py index 65a143f..4271266 100644 --- a/plugins/role/role.py +++ b/plugins/role/role.py @@ -45,10 +45,12 @@ class Role(Plugin): self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context self.roleplays = {} logger.info("[Role] inited") - except FileNotFoundError: - logger.warn(f"[Role] init failed, {config_path} not found, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role .") except Exception as e: - logger.warn("[Role] init failed, exception: %s, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role ." % e) + if isinstance(e, FileNotFoundError): + logger.warn(f"[Role] init failed, {config_path} not found, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role .") + else: + logger.warn("[Role] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role .") + raise e def get_role(self, name, find_closest=True): name = name.lower() diff --git a/plugins/sdwebui/sdwebui.py b/plugins/sdwebui/sdwebui.py index bbf99af..227f08e 100644 --- a/plugins/sdwebui/sdwebui.py +++ b/plugins/sdwebui/sdwebui.py @@ -29,10 +29,12 @@ class SDWebUI(Plugin): self.api = webuiapi.WebUIApi(**self.start_args) self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context logger.info("[SD] inited") - except FileNotFoundError: - logger.warn(f"[SD] init failed, {config_path} not found, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/sdwebui .") except Exception as e: - logger.warn("[SD] init failed, exception: %s, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/sdwebui ." % e) + if isinstance(e, FileNotFoundError): + logger.warn(f"[SD] init failed, {config_path} not found, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/sdwebui .") + else: + logger.warn("[SD] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/sdwebui .") + raise e def on_handle_context(self, e_context: EventContext):