From fb25005bd59fba4d35420a300f4ebcc11bd10b43 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sat, 24 Aug 2024 01:09:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=5F=5Fliteyuki=5Fplugin=5Fmeta=5F?= =?UTF-8?q?=5F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugin/load.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/liteyuki/plugin/load.py b/liteyuki/plugin/load.py index f944742a..6a2c5cf4 100644 --- a/liteyuki/plugin/load.py +++ b/liteyuki/plugin/load.py @@ -21,9 +21,9 @@ from liteyuki.utils import path_to_module_name _plugins: dict[str, Plugin] = {} __all__ = [ - "load_plugin", - "load_plugins", - "_plugins", + "load_plugin", + "load_plugins", + "_plugins", ] @@ -34,19 +34,32 @@ def load_plugin(module_path: str | Path) -> Optional[Plugin]: module_path: 插件名称 `path.to.your.plugin` 或插件路径 `pathlib.Path(path/to/your/plugin)` """ - module_path = path_to_module_name(Path(module_path)) if isinstance(module_path, Path) else module_path + module_path = ( + path_to_module_name(Path(module_path)) + if isinstance(module_path, Path) + else module_path + ) try: module = import_module(module_path) _plugins[module.__name__] = Plugin( name=module.__name__, module=module, module_name=module_path, - metadata=module.__dict__.get("__plugin_metadata__", None) + metadata=module.__dict__.get("__plugin_metadata__", None), ) display_name = module.__name__.split(".")[-1] - if module.__dict__.get("__plugin_meta__"): + if module.__dict__.get("__liteyuki_plugin_meta__"): + metadata: "PluginMetadata" = module.__dict__["__liteyuki_plugin_meta__"] + display_name = format_display_name( + f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type + ) + elif module.__dict__.get("__plugin_meta__"): metadata: "PluginMetadata" = module.__dict__["__plugin_meta__"] - display_name = format_display_name(f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type) + display_name = format_display_name( + f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type + ) + + # 那获取metadata有什么用?? logger.opt(colors=True).success( f'Succeeded to load liteyuki plugin "{display_name}"' @@ -90,10 +103,12 @@ def load_plugins(*plugin_dir: str, ignore_warning: bool = True) -> set[Plugin]: path = Path(os.path.join(dir_path, f)) module_name = None - if os.path.isfile(path) and f.endswith('.py') and f != '__init__.py': + if os.path.isfile(path) and f.endswith(".py") and f != "__init__.py": module_name = f"{path_to_module_name(Path(dir_path))}.{f[:-3]}" - elif os.path.isdir(path) and os.path.exists(os.path.join(path, '__init__.py')): + elif os.path.isdir(path) and os.path.exists( + os.path.join(path, "__init__.py") + ): module_name = path_to_module_name(path) if module_name: From 81c1d0286da310bc67e90268a4c2b5fd556ec511 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sat, 24 Aug 2024 01:14:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=87=E6=96=B0=E5=A2=9E=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=20liteyukibot-plugin-htmlrender=20=E4=BB=A5=E4=BE=BF?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=85=B6=E4=BB=96=E9=9C=80=E8=A6=81=20nonebo?= =?UTF-8?q?t-plugin-htmlrender=20=E6=B8=B2=E6=9F=93=E7=9A=84=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4071f33f..c379f4a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ nonebot-adapter-onebot~=2.4.3 nonebot-plugin-alconna~=0.46.3 nonebot_plugin_apscheduler~=0.4.0 nonebot-adapter-satori~=0.11.5 +liteyukibot-plugin-htmlrender~=0.1.0 pyppeteer~=2.0.0 markdown>=3.3.6 zhDateTime>=1.0.3 From 0defb00ede62e0f9d668ec69252b40e31c3043f6 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sat, 24 Aug 2024 01:43:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=A8=E6=96=B0=E5=A2=9E=E6=9C=AA?= =?UTF-8?q?=E6=8C=87=E5=AE=9Ametadata=E7=9A=84=E7=A9=BA=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugin/load.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/liteyuki/plugin/load.py b/liteyuki/plugin/load.py index 6a2c5cf4..a18cabe4 100644 --- a/liteyuki/plugin/load.py +++ b/liteyuki/plugin/load.py @@ -45,21 +45,32 @@ def load_plugin(module_path: str | Path) -> Optional[Plugin]: name=module.__name__, module=module, module_name=module_path, - metadata=module.__dict__.get("__plugin_metadata__", None), ) - display_name = module.__name__.split(".")[-1] - if module.__dict__.get("__liteyuki_plugin_meta__"): + if module.__dict__.get("__plugin_metadata__", None): + metadata: "PluginMetadata" = module.__dict__["__plugin_metadata__"] + display_name = module.__name__.split(".")[-1] + elif module.__dict__.get("__liteyuki_plugin_meta__", None): metadata: "PluginMetadata" = module.__dict__["__liteyuki_plugin_meta__"] display_name = format_display_name( f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type ) - elif module.__dict__.get("__plugin_meta__"): + elif module.__dict__.get("__plugin_meta__", None): metadata: "PluginMetadata" = module.__dict__["__plugin_meta__"] display_name = format_display_name( f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type ) - - # 那获取metadata有什么用?? + else: + + logger.opt(colors=True).warning( + f'The metadata of Liteyuki plugin "{module.__name__}" is not specified, use empty.' + ) + + metadata = PluginMetadata( + name=module.__name__, + ) + display_name = module.__name__.split(".")[-1] + + _plugins[module.__name__].metadata = metadata logger.opt(colors=True).success( f'Succeeded to load liteyuki plugin "{display_name}"'