From 73de429af1935aa95331c63218f8ecb7d7233d0f Mon Sep 17 00:00:00 2001 From: lanvent Date: Sun, 12 Mar 2023 12:57:27 +0800 Subject: [PATCH] import file with the same name as plugin --- plugins/hello/{main.py => hello.py} | 4 ++-- plugins/plugin_manager.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) rename plugins/hello/{main.py => hello.py} (92%) diff --git a/plugins/hello/main.py b/plugins/hello/hello.py similarity index 92% rename from plugins/hello/main.py rename to plugins/hello/hello.py index c7d8ee1..c380b96 100644 --- a/plugins/hello/main.py +++ b/plugins/hello/hello.py @@ -11,11 +11,11 @@ class Hello(Plugin): super().__init__() self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context # self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context - logger.info("[hello] inited") + logger.info("[Hello] inited") def on_handle_context(self, e_context: EventContext): - logger.debug("on_handle_context. content: %s" % e_context['context']['content']) + logger.debug("[Hello] on_handle_context. content: %s" % e_context['context']['content']) if e_context['context']['content'] == "Hello": e_context['reply']['type'] = "TEXT" diff --git a/plugins/plugin_manager.py b/plugins/plugin_manager.py index d4cda12..b7d88e7 100644 --- a/plugins/plugin_manager.py +++ b/plugins/plugin_manager.py @@ -38,11 +38,11 @@ class PluginManager: for plugin_name in os.listdir(plugins_dir): plugin_path = os.path.join(plugins_dir, plugin_name) if os.path.isdir(plugin_path): - # 判断插件是否包含main.py文件 - main_module_path = os.path.join(plugin_path, "main.py") + # 判断插件是否包含同名.py文件 + main_module_path = os.path.join(plugin_path, plugin_name+".py") if os.path.isfile(main_module_path): - # 导入插件的main - import_path = "{}.{}.main".format(plugins_dir, plugin_name) + # 导入插件 + import_path = "{}.{}.{}".format(plugins_dir, plugin_name, plugin_name) main_module = importlib.import_module(import_path) modified = False @@ -63,7 +63,7 @@ class PluginManager: def load_plugins(self): pconf = self.load_config() - + logger.debug("plugins.json config={}" % pconf) for plugin in pconf["plugins"]: name = plugin["name"] enabled = plugin["enabled"]