From 5d194b8ebe8b237b633d59b46d2cf520b35f8e1b Mon Sep 17 00:00:00 2001 From: snowy Date: Sun, 18 Aug 2024 08:06:06 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=B1=BB=E5=9E=8B=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugin/__init__.py | 3 +- liteyuki/plugin/load.py | 1 + liteyuki/plugin/model.py | 45 +++++++++++++++++-- .../__init__.py | 13 ++++-- .../dev_reloader.py | 2 + .../nb_utils/adapter_manager/__init__.py | 0 .../nb_utils/adapter_manager/onebot.py | 0 .../nb_utils/adapter_manager/satori.py | 0 .../nb_utils/driver_manager/__init__.py | 0 .../nb_utils/driver_manager/auto_set_env.py | 0 .../nb_utils/driver_manager/defines.py | 0 11 files changed, 57 insertions(+), 7 deletions(-) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/__init__.py (70%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/dev_reloader.py (93%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/adapter_manager/__init__.py (100%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/adapter_manager/onebot.py (100%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/adapter_manager/satori.py (100%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/driver_manager/__init__.py (100%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/driver_manager/auto_set_env.py (100%) rename src/liteyuki_plugins/{nonebot_launcher => liteyukibot_plugin_nonebot}/nb_utils/driver_manager/defines.py (100%) diff --git a/liteyuki/plugin/__init__.py b/liteyuki/plugin/__init__.py index 7bb7edf6..a8b9627b 100644 --- a/liteyuki/plugin/__init__.py +++ b/liteyuki/plugin/__init__.py @@ -1,9 +1,10 @@ -from liteyuki.plugin.model import Plugin, PluginMetadata +from liteyuki.plugin.model import Plugin, PluginMetadata, PluginType from liteyuki.plugin.load import load_plugin, load_plugins, _plugins __all__ = [ "PluginMetadata", "Plugin", + "PluginType", "load_plugin", "load_plugins", ] diff --git a/liteyuki/plugin/load.py b/liteyuki/plugin/load.py index a8cd6218..2c54822e 100644 --- a/liteyuki/plugin/load.py +++ b/liteyuki/plugin/load.py @@ -23,6 +23,7 @@ _plugins: dict[str, Plugin] = {} __all__ = [ "load_plugin", "load_plugins", + "_plugins", ] diff --git a/liteyuki/plugin/model.py b/liteyuki/plugin/model.py index a741415e..adabe144 100644 --- a/liteyuki/plugin/model.py +++ b/liteyuki/plugin/model.py @@ -8,22 +8,61 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @File : model.py @Software: PyCharm """ +from enum import Enum from types import ModuleType -from typing import Optional +from typing import Any, Optional from pydantic import BaseModel +class PluginType(Enum): + """ + 插件类型枚举值 + """ + APPLICATION = "application" + """应用端:例如NoneBot""" + + SERVICE = "service" + """服务端:例如AI绘画后端""" + + IMPLEMENTATION = "implementation" + """实现端:例如与聊天平台的协议实现""" + + MODULE = "module" + """模块:导出对象给其他插件使用""" + + UNCLASSIFIED = "unclassified" + """未分类:默认值""" + + class PluginMetadata(BaseModel): """ 轻雪插件元数据,由插件编写者提供,name为必填项 + Attributes: + ---------- + + name: str + 插件名称 + description: str + 插件描述 + usage: str + 插件使用方法 + type: str + 插件类型 + author: str + 插件作者 + homepage: str + 插件主页 + extra: dict[str, Any] + 额外信息 """ name: str description: str = "" usage: str = "" type: str = "" - homepage: str = "" - running_in_main: bool = True # 是否在主进程运行 + author: str = "" + homepage: str = PluginType.UNCLASSIFIED + extra: dict[str, Any] = {} class Plugin(BaseModel): diff --git a/src/liteyuki_plugins/nonebot_launcher/__init__.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/__init__.py similarity index 70% rename from src/liteyuki_plugins/nonebot_launcher/__init__.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/__init__.py index 31ff07ae..2aae4137 100644 --- a/src/liteyuki_plugins/nonebot_launcher/__init__.py +++ b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/__init__.py @@ -11,11 +11,12 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved import nonebot from liteyuki.utils import IS_MAIN_PROCESS -from liteyuki.plugin import PluginMetadata -from .nb_utils import adapter_manager, driver_manager +from liteyuki.plugin import PluginMetadata, PluginType +from .nb_utils import adapter_manager, driver_manager # type: ignore __plugin_meta__ = PluginMetadata( name="NoneBot2启动器", + type=PluginType.APPLICATION, ) @@ -35,7 +36,13 @@ def nb_run(*args, **kwargs): driver_manager.init(config=kwargs) adapter_manager.init(kwargs) adapter_manager.register() - nonebot.load_plugin("src.liteyuki_main") + + try: + # nonebot.load_plugin("nonebot-plugin-lnpm") # 尝试加载轻雪NoneBot插件加载器(Nonebot插件) + nonebot.load_plugin("src.liteyuki_main") # 尝试加载轻雪主插件(Nonebot插件) + except Exception as e: + pass + nonebot.run() diff --git a/src/liteyuki_plugins/nonebot_launcher/dev_reloader.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/dev_reloader.py similarity index 93% rename from src/liteyuki_plugins/nonebot_launcher/dev_reloader.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/dev_reloader.py index de378ef4..e299c16b 100644 --- a/src/liteyuki_plugins/nonebot_launcher/dev_reloader.py +++ b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/dev_reloader.py @@ -6,8 +6,10 @@ import os.path from liteyuki.dev import observer from liteyuki import get_bot, logger +from liteyuki.utils import IS_MAIN_PROCESS from watchdog.events import FileSystemEvent + liteyuki = get_bot() exclude_extensions = (".pyc", ".pyo") diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/__init__.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/__init__.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/__init__.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/__init__.py diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/onebot.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/onebot.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/onebot.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/onebot.py diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/satori.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/satori.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/adapter_manager/satori.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/adapter_manager/satori.py diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/__init__.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/__init__.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/__init__.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/__init__.py diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/auto_set_env.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/auto_set_env.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/auto_set_env.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/auto_set_env.py diff --git a/src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/defines.py b/src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/defines.py similarity index 100% rename from src/liteyuki_plugins/nonebot_launcher/nb_utils/driver_manager/defines.py rename to src/liteyuki_plugins/liteyukibot_plugin_nonebot/nb_utils/driver_manager/defines.py