mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-22 21:27:43 +08:00
✨ 新增插件类型枚举
This commit is contained in:
parent
78810d2ca8
commit
5d194b8ebe
@ -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
|
from liteyuki.plugin.load import load_plugin, load_plugins, _plugins
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"PluginMetadata",
|
"PluginMetadata",
|
||||||
"Plugin",
|
"Plugin",
|
||||||
|
"PluginType",
|
||||||
"load_plugin",
|
"load_plugin",
|
||||||
"load_plugins",
|
"load_plugins",
|
||||||
]
|
]
|
||||||
|
@ -23,6 +23,7 @@ _plugins: dict[str, Plugin] = {}
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"load_plugin",
|
"load_plugin",
|
||||||
"load_plugins",
|
"load_plugins",
|
||||||
|
"_plugins",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,22 +8,61 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
@File : model.py
|
@File : model.py
|
||||||
@Software: PyCharm
|
@Software: PyCharm
|
||||||
"""
|
"""
|
||||||
|
from enum import Enum
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class PluginType(Enum):
|
||||||
|
"""
|
||||||
|
插件类型枚举值
|
||||||
|
"""
|
||||||
|
APPLICATION = "application"
|
||||||
|
"""应用端:例如NoneBot"""
|
||||||
|
|
||||||
|
SERVICE = "service"
|
||||||
|
"""服务端:例如AI绘画后端"""
|
||||||
|
|
||||||
|
IMPLEMENTATION = "implementation"
|
||||||
|
"""实现端:例如与聊天平台的协议实现"""
|
||||||
|
|
||||||
|
MODULE = "module"
|
||||||
|
"""模块:导出对象给其他插件使用"""
|
||||||
|
|
||||||
|
UNCLASSIFIED = "unclassified"
|
||||||
|
"""未分类:默认值"""
|
||||||
|
|
||||||
|
|
||||||
class PluginMetadata(BaseModel):
|
class PluginMetadata(BaseModel):
|
||||||
"""
|
"""
|
||||||
轻雪插件元数据,由插件编写者提供,name为必填项
|
轻雪插件元数据,由插件编写者提供,name为必填项
|
||||||
|
Attributes:
|
||||||
|
----------
|
||||||
|
|
||||||
|
name: str
|
||||||
|
插件名称
|
||||||
|
description: str
|
||||||
|
插件描述
|
||||||
|
usage: str
|
||||||
|
插件使用方法
|
||||||
|
type: str
|
||||||
|
插件类型
|
||||||
|
author: str
|
||||||
|
插件作者
|
||||||
|
homepage: str
|
||||||
|
插件主页
|
||||||
|
extra: dict[str, Any]
|
||||||
|
额外信息
|
||||||
"""
|
"""
|
||||||
name: str
|
name: str
|
||||||
description: str = ""
|
description: str = ""
|
||||||
usage: str = ""
|
usage: str = ""
|
||||||
type: str = ""
|
type: str = ""
|
||||||
homepage: str = ""
|
author: str = ""
|
||||||
running_in_main: bool = True # 是否在主进程运行
|
homepage: str = PluginType.UNCLASSIFIED
|
||||||
|
extra: dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
class Plugin(BaseModel):
|
class Plugin(BaseModel):
|
||||||
|
@ -11,11 +11,12 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
|
|
||||||
import nonebot
|
import nonebot
|
||||||
from liteyuki.utils import IS_MAIN_PROCESS
|
from liteyuki.utils import IS_MAIN_PROCESS
|
||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
from .nb_utils import adapter_manager, driver_manager
|
from .nb_utils import adapter_manager, driver_manager # type: ignore
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="NoneBot2启动器",
|
name="NoneBot2启动器",
|
||||||
|
type=PluginType.APPLICATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +36,13 @@ def nb_run(*args, **kwargs):
|
|||||||
driver_manager.init(config=kwargs)
|
driver_manager.init(config=kwargs)
|
||||||
adapter_manager.init(kwargs)
|
adapter_manager.init(kwargs)
|
||||||
adapter_manager.register()
|
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()
|
nonebot.run()
|
||||||
|
|
||||||
|
|
@ -6,8 +6,10 @@ import os.path
|
|||||||
|
|
||||||
from liteyuki.dev import observer
|
from liteyuki.dev import observer
|
||||||
from liteyuki import get_bot, logger
|
from liteyuki import get_bot, logger
|
||||||
|
from liteyuki.utils import IS_MAIN_PROCESS
|
||||||
from watchdog.events import FileSystemEvent
|
from watchdog.events import FileSystemEvent
|
||||||
|
|
||||||
|
|
||||||
liteyuki = get_bot()
|
liteyuki = get_bot()
|
||||||
|
|
||||||
exclude_extensions = (".pyc", ".pyo")
|
exclude_extensions = (".pyc", ".pyo")
|
Loading…
Reference in New Issue
Block a user