diff --git a/.gitignore b/.gitignore index 1ab3337e..ecfd9505 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,9 @@ prompt.txt # pdm .pdm-python .pdm-build -dist \ No newline at end of file +dist + +doc + +mkdoc2.py +mkdoc.py \ No newline at end of file diff --git a/docs/.vuepress/sidebar/en.ts b/docs/.vuepress/sidebar/en.ts index 179eda79..46fe1aaf 100644 --- a/docs/.vuepress/sidebar/en.ts +++ b/docs/.vuepress/sidebar/en.ts @@ -1,31 +1,10 @@ import {sidebar} from "vuepress-theme-hope"; -export const enSidebarConfig = sidebar({ - "/en/": [ - "", - { - text: "Install & Deploy", - icon: "laptop-code", - prefix: "deploy/", - children: "structure", - }, - { - text: "Usage & Features", - icon: "book", - prefix: "usage/", - children: "structure", - }, - { - text: "Resources & Plugins", - icon: "store", - prefix: "store/", - children: "structure", - }, - { - text: "Development & Contribution", - icon: "pen-nib", - prefix: "dev/", - children: "structure", - } - ], -}); +export const enSidebarConfig = sidebar( + { + "/en/deploy/": "structure", + "/en/usage/": "structure", + "/en/store/": "structure", + "/en/dev/": "structure", + } +) diff --git a/docs/.vuepress/sidebar/zh.ts b/docs/.vuepress/sidebar/zh.ts index 01b8ded7..ce21071b 100644 --- a/docs/.vuepress/sidebar/zh.ts +++ b/docs/.vuepress/sidebar/zh.ts @@ -1,31 +1,11 @@ import {sidebar} from "vuepress-theme-hope"; -export const zhSidebarConfig = sidebar({ - "/": [ - "", - { - text: "安装及部署", - icon: "laptop-code", - prefix: "deploy/", - children: "structure", - }, - { - text: "使用及功能", - icon: "book", - prefix: "usage/", - children: "structure", - }, - { - text: "资源及插件", - icon: "store", - prefix: "store/", - children: "structure", - }, - { - text: "开发及贡献", - icon: "pen-nib", - prefix: "dev/", - children: "structure", - } - ], -}); + +export const zhSidebarConfig = sidebar( + { + "/deploy/": "structure", + "/usage/": "structure", + "/store/": "structure", + "/dev/": "structure", + } +) \ No newline at end of file diff --git a/docs/.vuepress/theme.ts b/docs/.vuepress/theme.ts index 368935d7..249938d9 100644 --- a/docs/.vuepress/theme.ts +++ b/docs/.vuepress/theme.ts @@ -5,6 +5,7 @@ import {enNavbarConfig, zhNavbarConfig} from "./navbar/index.js"; export default hopeTheme({ hostname: "https://vuepress-theme-hope-docs-demo.netlify.app", + hotReload: true, locales: { "/": { diff --git a/docs/dev/api/README.md b/docs/dev/api/README.md new file mode 100644 index 00000000..181ec73d --- /dev/null +++ b/docs/dev/api/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/dev/api/bot/README.md b/docs/dev/api/bot/README.md new file mode 100644 index 00000000..554e89a6 --- /dev/null +++ b/docs/dev/api/bot/README.md @@ -0,0 +1,225 @@ +--- +title: liteyuki.bot +index: true +icon: laptop-code +category: API +--- + +### ***def*** `get_bot() -> LiteyukiBot` + +获取轻雪实例 + +Returns: + LiteyukiBot: 当前的轻雪实例 + +### ***def*** `get_config(key: str, default: Any) -> Any` + +获取配置 +Args: + key: 配置键 + default: 默认值 + +Returns: + Any: 配置值 + +### ***def*** `get_config_with_compat(key: str, compat_keys: tuple[str], default: Any) -> Any` + +获取配置,兼容旧版本 +Args: + key: 配置键 + compat_keys: 兼容键 + default: 默认值 + +Returns: + Any: 配置值 + +### ***def*** `print_logo() -> None` + + + +### ***def*** `run(self: Any) -> None` + +启动逻辑 + +### ***def*** `keep_alive(self: Any) -> None` + +保持轻雪运行 +Returns: + +### ***def*** `restart(self: Any, delay: int) -> None` + +重启轻雪本体 +Returns: + +### ***def*** `restart_process(self: Any, name: Optional[str]) -> None` + +停止轻雪 +Args: + name: 进程名称, 默认为None, 所有进程 +Returns: + +### ***def*** `init(self: Any) -> None` + +初始化轻雪, 自动调用 +Returns: + +### ***def*** `init_logger(self: Any) -> None` + + + +### ***def*** `stop(self: Any) -> None` + +停止轻雪 +Returns: + +### ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> None` + +注册启动前的函数 +Args: + func: + +Returns: + +### ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> None` + +注册启动后的函数 +Args: + func: + +Returns: + +### ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + +注册停止后的函数:未实现 +Args: + func: + +Returns: + +### ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + +注册进程停止前的函数,为子进程停止时调用 +Args: + func: + +Returns: + +### ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> None` + +注册进程重启前的函数,为子进程重启时调用 +Args: + func: + +Returns: + +### ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> None` + +注册重启后的函数:未实现 +Args: + func: + +Returns: + +### ***def*** `on_after_nonebot_init(self: Any, func: LIFESPAN_FUNC) -> None` + +注册nonebot初始化后的函数 +Args: + func: + +Returns: + +### ***class*** `LiteyukiBot` + + + +####   ***def*** `run(self: Any) -> None` + + 启动逻辑 + +####   ***def*** `keep_alive(self: Any) -> None` + + 保持轻雪运行 +Returns: + +####   ***def*** `restart(self: Any, delay: int) -> None` + + 重启轻雪本体 +Returns: + +####   ***def*** `restart_process(self: Any, name: Optional[str]) -> None` + + 停止轻雪 +Args: + name: 进程名称, 默认为None, 所有进程 +Returns: + +####   ***def*** `init(self: Any) -> None` + + 初始化轻雪, 自动调用 +Returns: + +####   ***def*** `init_logger(self: Any) -> None` + + + +####   ***def*** `stop(self: Any) -> None` + + 停止轻雪 +Returns: + +####   ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册启动前的函数 +Args: + func: + +Returns: + +####   ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册启动后的函数 +Args: + func: + +Returns: + +####   ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册停止后的函数:未实现 +Args: + func: + +Returns: + +####   ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册进程停止前的函数,为子进程停止时调用 +Args: + func: + +Returns: + +####   ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册进程重启前的函数,为子进程重启时调用 +Args: + func: + +Returns: + +####   ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册重启后的函数:未实现 +Args: + func: + +Returns: + +####   ***def*** `on_after_nonebot_init(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册nonebot初始化后的函数 +Args: + func: + +Returns: + diff --git a/docs/dev/api/bot/lifespan.md b/docs/dev/api/bot/lifespan.md new file mode 100644 index 00000000..010f8dc0 --- /dev/null +++ b/docs/dev/api/bot/lifespan.md @@ -0,0 +1,201 @@ +--- +title: liteyuki.bot.lifespan +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None` + +运行函数 +Args: + funcs: +Returns: + +### ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册停止前的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册停止后的函数 +Args: + func: + +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册重启时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册重启后的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_nonebot_init(self: Any, func: Any) -> None` + +注册 NoneBot 初始化后的函数 +Args: + func: + +Returns: + +### ***def*** `before_start(self: Any) -> None` + +启动前 +Returns: + +### ***def*** `after_start(self: Any) -> None` + +启动后 +Returns: + +### ***def*** `before_process_shutdown(self: Any) -> None` + +停止前 +Returns: + +### ***def*** `after_shutdown(self: Any) -> None` + +停止后 +Returns: + +### ***def*** `before_process_restart(self: Any) -> None` + +重启前 +Returns: + +### ***def*** `after_restart(self: Any) -> None` + +重启后 +Returns: + +### ***class*** `Lifespan` + + + +#### `@staticmethod` + +####   ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None` + + 运行函数 +Args: + funcs: +Returns: + +####   ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册停止前的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册停止后的函数 +Args: + func: + +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册重启时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册重启后的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_nonebot_init(self: Any, func: Any) -> None` + + 注册 NoneBot 初始化后的函数 +Args: + func: + +Returns: + +####   ***def*** `before_start(self: Any) -> None` + + 启动前 +Returns: + +####   ***def*** `after_start(self: Any) -> None` + + 启动后 +Returns: + +####   ***def*** `before_process_shutdown(self: Any) -> None` + + 停止前 +Returns: + +####   ***def*** `after_shutdown(self: Any) -> None` + + 停止后 +Returns: + +####   ***def*** `before_process_restart(self: Any) -> None` + + 重启前 +Returns: + +####   ***def*** `after_restart(self: Any) -> None` + + 重启后 +Returns: + diff --git a/docs/dev/api/comm/README.md b/docs/dev/api/comm/README.md new file mode 100644 index 00000000..09bccc34 --- /dev/null +++ b/docs/dev/api/comm/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.comm +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/dev/api/comm/channel.md b/docs/dev/api/comm/channel.md new file mode 100644 index 00000000..ac22ded8 --- /dev/null +++ b/docs/dev/api/comm/channel.md @@ -0,0 +1,103 @@ +--- +title: liteyuki.comm.channel +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `set_channel(name: str, channel: Channel) -> None` + +设置通道实例 +Args: + name: 通道名称 + channel: 通道实例 + +### ***def*** `set_channels(channels: dict[str, Channel]) -> None` + +设置通道实例 +Args: + channels: 通道名称 + +### ***def*** `get_channel(name: str) -> Channel` + +获取通道实例 +Args: + name: 通道名称 +Returns: + +### ***def*** `get_channels() -> dict[str, Channel]` + +获取通道实例 +Returns: + +### ***def*** `send(self: Any, data: T) -> None` + +发送数据 +Args: + data: 数据 + +### ***def*** `receive(self: Any) -> T` + +接收数据 +Args: + +### ***def*** `close(self: Any) -> None` + +关闭通道 + +### ***def*** `on_receive(self: Any, filter_func: Optional[FILTER_FUNC]) -> Callable[[Callable[[T], Any]], Callable[[T], Any]]` + +接收数据并执行函数 +Args: + filter_func: 过滤函数,为None则不过滤 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + +### ***def*** `on_set_channel(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_channel(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_channels(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `decorator(func: Callable[[T], Any]) -> Callable[[T], Any]` + + + +### ***async def*** `wrapper(data: T) -> Any` + + + +### ***class*** `Channel(Generic[T])` + +通道类,可以在进程间和进程内通信,双向但同时只能有一个发送者和一个接收者 +有两种接收工作方式,但是只能选择一种,主动接收和被动接收,主动接收使用 `receive` 方法,被动接收使用 `on_receive` 装饰器 + +####   ***def*** `send(self: Any, data: T) -> None` + + 发送数据 +Args: + data: 数据 + +####   ***def*** `receive(self: Any) -> T` + + 接收数据 +Args: + +####   ***def*** `close(self: Any) -> None` + + 关闭通道 + +####   ***def*** `on_receive(self: Any, filter_func: Optional[FILTER_FUNC]) -> Callable[[Callable[[T], Any]], Callable[[T], Any]]` + + 接收数据并执行函数 +Args: + filter_func: 过滤函数,为None则不过滤 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + diff --git a/docs/dev/api/comm/event.md b/docs/dev/api/comm/event.md new file mode 100644 index 00000000..89bd331f --- /dev/null +++ b/docs/dev/api/comm/event.md @@ -0,0 +1,11 @@ +--- +title: liteyuki.comm.event +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `Event` + +事件类 + diff --git a/docs/dev/api/comm/storage.md b/docs/dev/api/comm/storage.md new file mode 100644 index 00000000..e0536ff3 --- /dev/null +++ b/docs/dev/api/comm/storage.md @@ -0,0 +1,113 @@ +--- +title: liteyuki.comm.storage +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `set(self: Any, key: str, value: Any) -> None` + +设置键值对 +Args: + key: 键 + value: 值 + +### ***def*** `get(self: Any, key: str, default: Optional[Any]) -> Optional[Any]` + +获取键值对 +Args: + key: 键 + default: 默认值 + +Returns: + Any: 值 + +### ***def*** `delete(self: Any, key: str, ignore_key_error: bool) -> None` + +删除键值对 +Args: + key: 键 + ignore_key_error: 是否忽略键不存在的错误 + +Returns: + +### ***def*** `get_all(self: Any) -> dict[str, Any]` + +获取所有键值对 +Returns: + dict[str, Any]: 键值对 + +### ***def*** `get_instance(cls: Any) -> None` + + + +### ***def*** `on_get(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_set(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_delete(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_all(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***class*** `KeyValueStore` + + + +####   ***def*** `set(self: Any, key: str, value: Any) -> None` + + 设置键值对 +Args: + key: 键 + value: 值 + +####   ***def*** `get(self: Any, key: str, default: Optional[Any]) -> Optional[Any]` + + 获取键值对 +Args: + key: 键 + default: 默认值 + +Returns: + Any: 值 + +####   ***def*** `delete(self: Any, key: str, ignore_key_error: bool) -> None` + + 删除键值对 +Args: + key: 键 + ignore_key_error: 是否忽略键不存在的错误 + +Returns: + +####   ***def*** `get_all(self: Any) -> dict[str, Any]` + + 获取所有键值对 +Returns: + dict[str, Any]: 键值对 + +### ***class*** `GlobalKeyValueStore` + + + +#### `@classmethod` + +####   ***def*** `get_instance(cls: Any) -> None` + + + +####   ***attr*** `_instance` + + Type: None + +####   ***attr*** `_lock` + + Type: threading.Lock() + diff --git a/docs/dev/api/config.md b/docs/dev/api/config.md new file mode 100644 index 00000000..87f8ff96 --- /dev/null +++ b/docs/dev/api/config.md @@ -0,0 +1,59 @@ +--- +title: liteyuki.config +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `flat_config(config: dict[str, Any]) -> dict[str, Any]` + +扁平化配置文件 + +{a:{b:{c:1}}} -> {"a.b.c": 1} +Args: + config: 配置项目 + +Returns: + 扁平化后的配置文件,但也包含原有的键值对 + +### ***def*** `load_from_yaml(file: str) -> dict[str, Any]` + +Load config from yaml file + +### ***def*** `load_from_json(file: str) -> dict[str, Any]` + +Load config from json file + +### ***def*** `load_from_toml(file: str) -> dict[str, Any]` + +Load config from toml file + +### ***def*** `load_from_files() -> dict[str, Any]` + +从指定文件加载配置项,会自动识别文件格式 +默认执行扁平化选项 + +### ***def*** `load_configs_from_dirs() -> dict[str, Any]` + +从目录下加载配置文件,不递归 +按照读取文件的优先级反向覆盖 +默认执行扁平化选项 + +### ***def*** `load_config_in_default(no_waring: bool) -> dict[str, Any]` + +从一个标准的轻雪项目加载配置文件 +项目目录下的config.*和config目录下的所有配置文件 +项目目录下的配置文件优先 + +### ***class*** `SatoriNodeConfig(BaseModel)` + + + +### ***class*** `SatoriConfig(BaseModel)` + + + +### ***class*** `BasicConfig(BaseModel)` + + + diff --git a/docs/dev/api/core/README.md b/docs/dev/api/core/README.md new file mode 100644 index 00000000..26c3500b --- /dev/null +++ b/docs/dev/api/core/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.core +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/dev/api/core/manager.md b/docs/dev/api/core/manager.md new file mode 100644 index 00000000..5bfd65c1 --- /dev/null +++ b/docs/dev/api/core/manager.md @@ -0,0 +1,103 @@ +--- +title: liteyuki.core.manager +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `start(self: Any, name: str) -> None` + +开启后自动监控进程,并添加到进程字典中 +Args: + name: +Returns: + +### ***def*** `start_all(self: Any) -> None` + +启动所有进程 + +### ***def*** `add_target(self: Any, name: str, target: TARGET_FUNC, args: tuple, kwargs: Any) -> None` + +添加进程 +Args: + name: 进程名,用于获取和唯一标识 + target: 进程函数 + args: 进程函数参数 + kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive + +### ***def*** `join_all(self: Any) -> None` + + + +### ***def*** `terminate(self: Any, name: str) -> None` + +终止进程并从进程字典中删除 +Args: + name: + +Returns: + +### ***def*** `terminate_all(self: Any) -> None` + + + +### ***def*** `is_process_alive(self: Any, name: str) -> bool` + +检查进程是否存活 +Args: + name: + +Returns: + +### ***class*** `ChannelDeliver` + + + +### ***class*** `ProcessManager` + +进程管理器 + +####   ***def*** `start(self: Any, name: str) -> None` + + 开启后自动监控进程,并添加到进程字典中 +Args: + name: +Returns: + +####   ***def*** `start_all(self: Any) -> None` + + 启动所有进程 + +####   ***def*** `add_target(self: Any, name: str, target: TARGET_FUNC, args: tuple, kwargs: Any) -> None` + + 添加进程 +Args: + name: 进程名,用于获取和唯一标识 + target: 进程函数 + args: 进程函数参数 + kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive + +####   ***def*** `join_all(self: Any) -> None` + + + +####   ***def*** `terminate(self: Any, name: str) -> None` + + 终止进程并从进程字典中删除 +Args: + name: + +Returns: + +####   ***def*** `terminate_all(self: Any) -> None` + + + +####   ***def*** `is_process_alive(self: Any, name: str) -> bool` + + 检查进程是否存活 +Args: + name: + +Returns: + diff --git a/docs/dev/api/dev/README.md b/docs/dev/api/dev/README.md new file mode 100644 index 00000000..6d883442 --- /dev/null +++ b/docs/dev/api/dev/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.dev +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/dev/api/dev/observer.md b/docs/dev/api/dev/observer.md new file mode 100644 index 00000000..b1f54c41 --- /dev/null +++ b/docs/dev/api/dev/observer.md @@ -0,0 +1,81 @@ +--- +title: liteyuki.dev.observer +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `debounce(wait: Any) -> None` + +防抖函数 + +### ***def*** `on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]` + +注册文件系统变化监听器 +Args: + directories: 监听目录们 + recursive: 是否递归监听子目录 + event_filter: 事件过滤器, 返回True则执行回调函数 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + +### ***def*** `decorator(func: Any) -> None` + + + +### ***def*** `on_modified(self: Any, event: Any) -> None` + + + +### ***def*** `on_created(self: Any, event: Any) -> None` + + + +### ***def*** `on_deleted(self: Any, event: Any) -> None` + + + +### ***def*** `on_moved(self: Any, event: Any) -> None` + + + +### ***def*** `on_any_event(self: Any, event: Any) -> None` + + + +### ***def*** `decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC` + + + +### ***def*** `wrapper() -> None` + + + +### ***def*** `wrapper(event: FileSystemEvent) -> None` + + + +### ***class*** `CodeModifiedHandler(FileSystemEventHandler)` + +Handler for code file changes + +####   ***def*** `on_modified(self: Any, event: Any) -> None` + + + +####   ***def*** `on_created(self: Any, event: Any) -> None` + + + +####   ***def*** `on_deleted(self: Any, event: Any) -> None` + + + +####   ***def*** `on_moved(self: Any, event: Any) -> None` + + + +####   ***def*** `on_any_event(self: Any, event: Any) -> None` + + + diff --git a/docs/dev/api/dev/plugin.md b/docs/dev/api/dev/plugin.md new file mode 100644 index 00000000..40f118f5 --- /dev/null +++ b/docs/dev/api/dev/plugin.md @@ -0,0 +1,13 @@ +--- +title: liteyuki.dev.plugin +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `run_plugins() -> None` + +运行插件,无需手动初始化bot +Args: + module_path: 插件路径,参考`liteyuki.load_plugin`的函数签名 + diff --git a/docs/dev/api/exception.md b/docs/dev/api/exception.md new file mode 100644 index 00000000..469c00d6 --- /dev/null +++ b/docs/dev/api/exception.md @@ -0,0 +1,11 @@ +--- +title: liteyuki.exception +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `LiteyukiException(BaseException)` + +Liteyuki的异常基类。 + diff --git a/docs/dev/api/log.md b/docs/dev/api/log.md new file mode 100644 index 00000000..30812a21 --- /dev/null +++ b/docs/dev/api/log.md @@ -0,0 +1,16 @@ +--- +title: liteyuki.log +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `get_format(level: str) -> str` + + + +### ***def*** `init_log(config: dict) -> None` + +在语言加载完成后执行 +Returns: + diff --git a/docs/dev/api/plugin/README.md b/docs/dev/api/plugin/README.md new file mode 100644 index 00000000..aa484ffd --- /dev/null +++ b/docs/dev/api/plugin/README.md @@ -0,0 +1,13 @@ +--- +title: liteyuki.plugin +index: true +icon: laptop-code +category: API +--- + +### ***def*** `get_loaded_plugins() -> dict[str, Plugin]` + +获取已加载的插件 +Returns: + dict[str, Plugin]: 插件字典 + diff --git a/docs/dev/api/plugin/load.md b/docs/dev/api/plugin/load.md new file mode 100644 index 00000000..465bf82d --- /dev/null +++ b/docs/dev/api/plugin/load.md @@ -0,0 +1,33 @@ +--- +title: liteyuki.plugin.load +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `load_plugin(module_path: str | Path) -> Optional[Plugin]` + +加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。 + +参数: + module_path: 插件名称 `path.to.your.plugin` + 或插件路径 `pathlib.Path(path/to/your/plugin)` + +### ***def*** `load_plugins() -> set[Plugin]` + +导入文件夹下多个插件 + +参数: + plugin_dir: 文件夹路径 + ignore_warning: 是否忽略警告,通常是目录不存在或目录为空 + +### ***def*** `format_display_name(display_name: str, plugin_type: PluginType) -> str` + +设置插件名称颜色,根据不同类型插件设置颜色 +Args: + display_name: 插件名称 + plugin_type: 插件类型 + +Returns: + str: 设置后的插件名称 name + diff --git a/docs/dev/api/plugin/manager.md b/docs/dev/api/plugin/manager.md new file mode 100644 index 00000000..7d4d951c --- /dev/null +++ b/docs/dev/api/plugin/manager.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.plugin.manager +order: 1 +icon: laptop-code +category: API +--- + diff --git a/docs/dev/api/plugin/model.md b/docs/dev/api/plugin/model.md new file mode 100644 index 00000000..1f17b2d3 --- /dev/null +++ b/docs/dev/api/plugin/model.md @@ -0,0 +1,60 @@ +--- +title: liteyuki.plugin.model +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `PluginType(Enum)` + +插件类型枚举值 + +####   ***attr*** `APPLICATION` + + Type: 'application' + +####   ***attr*** `SERVICE` + + Type: 'service' + +####   ***attr*** `IMPLEMENTATION` + + Type: 'implementation' + +####   ***attr*** `MODULE` + + Type: 'module' + +####   ***attr*** `UNCLASSIFIED` + + Type: 'unclassified' + +### ***class*** `PluginMetadata(BaseModel)` + +轻雪插件元数据,由插件编写者提供,name为必填项 +Attributes: +---------- + +name: str + 插件名称 +description: str + 插件描述 +usage: str + 插件使用方法 +type: str + 插件类型 +author: str + 插件作者 +homepage: str + 插件主页 +extra: dict[str, Any] + 额外信息 + +### ***class*** `Plugin(BaseModel)` + +存储插件信息 + +####   ***attr*** `model_config` + + Type: {'arbitrary_types_allowed': True} + diff --git a/docs/dev/api/utils.md b/docs/dev/api/utils.md new file mode 100644 index 00000000..e8767e15 --- /dev/null +++ b/docs/dev/api/utils.md @@ -0,0 +1,43 @@ +--- +title: liteyuki.utils +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `is_coroutine_callable(call: Callable[..., Any]) -> bool` + +判断是否为协程可调用对象 +Args: + call: 可调用对象 +Returns: + bool: 是否为协程可调用对象 + +### ***def*** `run_coroutine() -> None` + +运行协程 +Args: + coro: + +Returns: + +### ***def*** `path_to_module_name(path: Path) -> str` + +转换路径为模块名 +Args: + path: 路径a/b/c/d -> a.b.c.d +Returns: + str: 模块名 + +### ***def*** `async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]` + +异步包装器 +Args: + func: Sync Callable +Returns: + Coroutine: Asynchronous Callable + +### ***async def*** `wrapper() -> None` + + + diff --git a/docs/en/dev/api/liteyuki/README.md b/docs/en/dev/api/liteyuki/README.md new file mode 100644 index 00000000..181ec73d --- /dev/null +++ b/docs/en/dev/api/liteyuki/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/en/dev/api/liteyuki/bot/README.md b/docs/en/dev/api/liteyuki/bot/README.md new file mode 100644 index 00000000..554e89a6 --- /dev/null +++ b/docs/en/dev/api/liteyuki/bot/README.md @@ -0,0 +1,225 @@ +--- +title: liteyuki.bot +index: true +icon: laptop-code +category: API +--- + +### ***def*** `get_bot() -> LiteyukiBot` + +获取轻雪实例 + +Returns: + LiteyukiBot: 当前的轻雪实例 + +### ***def*** `get_config(key: str, default: Any) -> Any` + +获取配置 +Args: + key: 配置键 + default: 默认值 + +Returns: + Any: 配置值 + +### ***def*** `get_config_with_compat(key: str, compat_keys: tuple[str], default: Any) -> Any` + +获取配置,兼容旧版本 +Args: + key: 配置键 + compat_keys: 兼容键 + default: 默认值 + +Returns: + Any: 配置值 + +### ***def*** `print_logo() -> None` + + + +### ***def*** `run(self: Any) -> None` + +启动逻辑 + +### ***def*** `keep_alive(self: Any) -> None` + +保持轻雪运行 +Returns: + +### ***def*** `restart(self: Any, delay: int) -> None` + +重启轻雪本体 +Returns: + +### ***def*** `restart_process(self: Any, name: Optional[str]) -> None` + +停止轻雪 +Args: + name: 进程名称, 默认为None, 所有进程 +Returns: + +### ***def*** `init(self: Any) -> None` + +初始化轻雪, 自动调用 +Returns: + +### ***def*** `init_logger(self: Any) -> None` + + + +### ***def*** `stop(self: Any) -> None` + +停止轻雪 +Returns: + +### ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> None` + +注册启动前的函数 +Args: + func: + +Returns: + +### ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> None` + +注册启动后的函数 +Args: + func: + +Returns: + +### ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + +注册停止后的函数:未实现 +Args: + func: + +Returns: + +### ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + +注册进程停止前的函数,为子进程停止时调用 +Args: + func: + +Returns: + +### ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> None` + +注册进程重启前的函数,为子进程重启时调用 +Args: + func: + +Returns: + +### ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> None` + +注册重启后的函数:未实现 +Args: + func: + +Returns: + +### ***def*** `on_after_nonebot_init(self: Any, func: LIFESPAN_FUNC) -> None` + +注册nonebot初始化后的函数 +Args: + func: + +Returns: + +### ***class*** `LiteyukiBot` + + + +####   ***def*** `run(self: Any) -> None` + + 启动逻辑 + +####   ***def*** `keep_alive(self: Any) -> None` + + 保持轻雪运行 +Returns: + +####   ***def*** `restart(self: Any, delay: int) -> None` + + 重启轻雪本体 +Returns: + +####   ***def*** `restart_process(self: Any, name: Optional[str]) -> None` + + 停止轻雪 +Args: + name: 进程名称, 默认为None, 所有进程 +Returns: + +####   ***def*** `init(self: Any) -> None` + + 初始化轻雪, 自动调用 +Returns: + +####   ***def*** `init_logger(self: Any) -> None` + + + +####   ***def*** `stop(self: Any) -> None` + + 停止轻雪 +Returns: + +####   ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册启动前的函数 +Args: + func: + +Returns: + +####   ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册启动后的函数 +Args: + func: + +Returns: + +####   ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册停止后的函数:未实现 +Args: + func: + +Returns: + +####   ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册进程停止前的函数,为子进程停止时调用 +Args: + func: + +Returns: + +####   ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册进程重启前的函数,为子进程重启时调用 +Args: + func: + +Returns: + +####   ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册重启后的函数:未实现 +Args: + func: + +Returns: + +####   ***def*** `on_after_nonebot_init(self: Any, func: LIFESPAN_FUNC) -> None` + + 注册nonebot初始化后的函数 +Args: + func: + +Returns: + diff --git a/docs/en/dev/api/liteyuki/bot/lifespan.md b/docs/en/dev/api/liteyuki/bot/lifespan.md new file mode 100644 index 00000000..010f8dc0 --- /dev/null +++ b/docs/en/dev/api/liteyuki/bot/lifespan.md @@ -0,0 +1,201 @@ +--- +title: liteyuki.bot.lifespan +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None` + +运行函数 +Args: + funcs: +Returns: + +### ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册停止前的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册停止后的函数 +Args: + func: + +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册重启时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + +注册重启后的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +### ***def*** `on_after_nonebot_init(self: Any, func: Any) -> None` + +注册 NoneBot 初始化后的函数 +Args: + func: + +Returns: + +### ***def*** `before_start(self: Any) -> None` + +启动前 +Returns: + +### ***def*** `after_start(self: Any) -> None` + +启动后 +Returns: + +### ***def*** `before_process_shutdown(self: Any) -> None` + +停止前 +Returns: + +### ***def*** `after_shutdown(self: Any) -> None` + +停止后 +Returns: + +### ***def*** `before_process_restart(self: Any) -> None` + +重启前 +Returns: + +### ***def*** `after_restart(self: Any) -> None` + +重启后 +Returns: + +### ***class*** `Lifespan` + + + +#### `@staticmethod` + +####   ***def*** `run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None` + + 运行函数 +Args: + funcs: +Returns: + +####   ***def*** `on_before_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_start(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册启动时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_before_process_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册停止前的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_shutdown(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册停止后的函数 +Args: + func: + +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_before_process_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册重启时的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_restart(self: Any, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC` + + 注册重启后的函数 +Args: + func: +Returns: + LIFESPAN_FUNC: + +####   ***def*** `on_after_nonebot_init(self: Any, func: Any) -> None` + + 注册 NoneBot 初始化后的函数 +Args: + func: + +Returns: + +####   ***def*** `before_start(self: Any) -> None` + + 启动前 +Returns: + +####   ***def*** `after_start(self: Any) -> None` + + 启动后 +Returns: + +####   ***def*** `before_process_shutdown(self: Any) -> None` + + 停止前 +Returns: + +####   ***def*** `after_shutdown(self: Any) -> None` + + 停止后 +Returns: + +####   ***def*** `before_process_restart(self: Any) -> None` + + 重启前 +Returns: + +####   ***def*** `after_restart(self: Any) -> None` + + 重启后 +Returns: + diff --git a/docs/en/dev/api/liteyuki/comm/README.md b/docs/en/dev/api/liteyuki/comm/README.md new file mode 100644 index 00000000..09bccc34 --- /dev/null +++ b/docs/en/dev/api/liteyuki/comm/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.comm +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/en/dev/api/liteyuki/comm/channel.md b/docs/en/dev/api/liteyuki/comm/channel.md new file mode 100644 index 00000000..ac22ded8 --- /dev/null +++ b/docs/en/dev/api/liteyuki/comm/channel.md @@ -0,0 +1,103 @@ +--- +title: liteyuki.comm.channel +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `set_channel(name: str, channel: Channel) -> None` + +设置通道实例 +Args: + name: 通道名称 + channel: 通道实例 + +### ***def*** `set_channels(channels: dict[str, Channel]) -> None` + +设置通道实例 +Args: + channels: 通道名称 + +### ***def*** `get_channel(name: str) -> Channel` + +获取通道实例 +Args: + name: 通道名称 +Returns: + +### ***def*** `get_channels() -> dict[str, Channel]` + +获取通道实例 +Returns: + +### ***def*** `send(self: Any, data: T) -> None` + +发送数据 +Args: + data: 数据 + +### ***def*** `receive(self: Any) -> T` + +接收数据 +Args: + +### ***def*** `close(self: Any) -> None` + +关闭通道 + +### ***def*** `on_receive(self: Any, filter_func: Optional[FILTER_FUNC]) -> Callable[[Callable[[T], Any]], Callable[[T], Any]]` + +接收数据并执行函数 +Args: + filter_func: 过滤函数,为None则不过滤 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + +### ***def*** `on_set_channel(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_channel(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_channels(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `decorator(func: Callable[[T], Any]) -> Callable[[T], Any]` + + + +### ***async def*** `wrapper(data: T) -> Any` + + + +### ***class*** `Channel(Generic[T])` + +通道类,可以在进程间和进程内通信,双向但同时只能有一个发送者和一个接收者 +有两种接收工作方式,但是只能选择一种,主动接收和被动接收,主动接收使用 `receive` 方法,被动接收使用 `on_receive` 装饰器 + +####   ***def*** `send(self: Any, data: T) -> None` + + 发送数据 +Args: + data: 数据 + +####   ***def*** `receive(self: Any) -> T` + + 接收数据 +Args: + +####   ***def*** `close(self: Any) -> None` + + 关闭通道 + +####   ***def*** `on_receive(self: Any, filter_func: Optional[FILTER_FUNC]) -> Callable[[Callable[[T], Any]], Callable[[T], Any]]` + + 接收数据并执行函数 +Args: + filter_func: 过滤函数,为None则不过滤 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + diff --git a/docs/en/dev/api/liteyuki/comm/event.md b/docs/en/dev/api/liteyuki/comm/event.md new file mode 100644 index 00000000..89bd331f --- /dev/null +++ b/docs/en/dev/api/liteyuki/comm/event.md @@ -0,0 +1,11 @@ +--- +title: liteyuki.comm.event +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `Event` + +事件类 + diff --git a/docs/en/dev/api/liteyuki/comm/storage.md b/docs/en/dev/api/liteyuki/comm/storage.md new file mode 100644 index 00000000..e0536ff3 --- /dev/null +++ b/docs/en/dev/api/liteyuki/comm/storage.md @@ -0,0 +1,113 @@ +--- +title: liteyuki.comm.storage +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `set(self: Any, key: str, value: Any) -> None` + +设置键值对 +Args: + key: 键 + value: 值 + +### ***def*** `get(self: Any, key: str, default: Optional[Any]) -> Optional[Any]` + +获取键值对 +Args: + key: 键 + default: 默认值 + +Returns: + Any: 值 + +### ***def*** `delete(self: Any, key: str, ignore_key_error: bool) -> None` + +删除键值对 +Args: + key: 键 + ignore_key_error: 是否忽略键不存在的错误 + +Returns: + +### ***def*** `get_all(self: Any) -> dict[str, Any]` + +获取所有键值对 +Returns: + dict[str, Any]: 键值对 + +### ***def*** `get_instance(cls: Any) -> None` + + + +### ***def*** `on_get(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_set(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_delete(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***def*** `on_get_all(data: tuple[str, dict[str, Any]]) -> None` + + + +### ***class*** `KeyValueStore` + + + +####   ***def*** `set(self: Any, key: str, value: Any) -> None` + + 设置键值对 +Args: + key: 键 + value: 值 + +####   ***def*** `get(self: Any, key: str, default: Optional[Any]) -> Optional[Any]` + + 获取键值对 +Args: + key: 键 + default: 默认值 + +Returns: + Any: 值 + +####   ***def*** `delete(self: Any, key: str, ignore_key_error: bool) -> None` + + 删除键值对 +Args: + key: 键 + ignore_key_error: 是否忽略键不存在的错误 + +Returns: + +####   ***def*** `get_all(self: Any) -> dict[str, Any]` + + 获取所有键值对 +Returns: + dict[str, Any]: 键值对 + +### ***class*** `GlobalKeyValueStore` + + + +#### `@classmethod` + +####   ***def*** `get_instance(cls: Any) -> None` + + + +####   ***attr*** `_instance` + + Type: None + +####   ***attr*** `_lock` + + Type: threading.Lock() + diff --git a/docs/en/dev/api/liteyuki/config.md b/docs/en/dev/api/liteyuki/config.md new file mode 100644 index 00000000..87f8ff96 --- /dev/null +++ b/docs/en/dev/api/liteyuki/config.md @@ -0,0 +1,59 @@ +--- +title: liteyuki.config +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `flat_config(config: dict[str, Any]) -> dict[str, Any]` + +扁平化配置文件 + +{a:{b:{c:1}}} -> {"a.b.c": 1} +Args: + config: 配置项目 + +Returns: + 扁平化后的配置文件,但也包含原有的键值对 + +### ***def*** `load_from_yaml(file: str) -> dict[str, Any]` + +Load config from yaml file + +### ***def*** `load_from_json(file: str) -> dict[str, Any]` + +Load config from json file + +### ***def*** `load_from_toml(file: str) -> dict[str, Any]` + +Load config from toml file + +### ***def*** `load_from_files() -> dict[str, Any]` + +从指定文件加载配置项,会自动识别文件格式 +默认执行扁平化选项 + +### ***def*** `load_configs_from_dirs() -> dict[str, Any]` + +从目录下加载配置文件,不递归 +按照读取文件的优先级反向覆盖 +默认执行扁平化选项 + +### ***def*** `load_config_in_default(no_waring: bool) -> dict[str, Any]` + +从一个标准的轻雪项目加载配置文件 +项目目录下的config.*和config目录下的所有配置文件 +项目目录下的配置文件优先 + +### ***class*** `SatoriNodeConfig(BaseModel)` + + + +### ***class*** `SatoriConfig(BaseModel)` + + + +### ***class*** `BasicConfig(BaseModel)` + + + diff --git a/docs/en/dev/api/liteyuki/core/README.md b/docs/en/dev/api/liteyuki/core/README.md new file mode 100644 index 00000000..26c3500b --- /dev/null +++ b/docs/en/dev/api/liteyuki/core/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.core +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/en/dev/api/liteyuki/core/manager.md b/docs/en/dev/api/liteyuki/core/manager.md new file mode 100644 index 00000000..5bfd65c1 --- /dev/null +++ b/docs/en/dev/api/liteyuki/core/manager.md @@ -0,0 +1,103 @@ +--- +title: liteyuki.core.manager +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `start(self: Any, name: str) -> None` + +开启后自动监控进程,并添加到进程字典中 +Args: + name: +Returns: + +### ***def*** `start_all(self: Any) -> None` + +启动所有进程 + +### ***def*** `add_target(self: Any, name: str, target: TARGET_FUNC, args: tuple, kwargs: Any) -> None` + +添加进程 +Args: + name: 进程名,用于获取和唯一标识 + target: 进程函数 + args: 进程函数参数 + kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive + +### ***def*** `join_all(self: Any) -> None` + + + +### ***def*** `terminate(self: Any, name: str) -> None` + +终止进程并从进程字典中删除 +Args: + name: + +Returns: + +### ***def*** `terminate_all(self: Any) -> None` + + + +### ***def*** `is_process_alive(self: Any, name: str) -> bool` + +检查进程是否存活 +Args: + name: + +Returns: + +### ***class*** `ChannelDeliver` + + + +### ***class*** `ProcessManager` + +进程管理器 + +####   ***def*** `start(self: Any, name: str) -> None` + + 开启后自动监控进程,并添加到进程字典中 +Args: + name: +Returns: + +####   ***def*** `start_all(self: Any) -> None` + + 启动所有进程 + +####   ***def*** `add_target(self: Any, name: str, target: TARGET_FUNC, args: tuple, kwargs: Any) -> None` + + 添加进程 +Args: + name: 进程名,用于获取和唯一标识 + target: 进程函数 + args: 进程函数参数 + kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive + +####   ***def*** `join_all(self: Any) -> None` + + + +####   ***def*** `terminate(self: Any, name: str) -> None` + + 终止进程并从进程字典中删除 +Args: + name: + +Returns: + +####   ***def*** `terminate_all(self: Any) -> None` + + + +####   ***def*** `is_process_alive(self: Any, name: str) -> bool` + + 检查进程是否存活 +Args: + name: + +Returns: + diff --git a/docs/en/dev/api/liteyuki/dev/README.md b/docs/en/dev/api/liteyuki/dev/README.md new file mode 100644 index 00000000..6d883442 --- /dev/null +++ b/docs/en/dev/api/liteyuki/dev/README.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.dev +index: true +icon: laptop-code +category: API +--- + diff --git a/docs/en/dev/api/liteyuki/dev/observer.md b/docs/en/dev/api/liteyuki/dev/observer.md new file mode 100644 index 00000000..b1f54c41 --- /dev/null +++ b/docs/en/dev/api/liteyuki/dev/observer.md @@ -0,0 +1,81 @@ +--- +title: liteyuki.dev.observer +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `debounce(wait: Any) -> None` + +防抖函数 + +### ***def*** `on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]` + +注册文件系统变化监听器 +Args: + directories: 监听目录们 + recursive: 是否递归监听子目录 + event_filter: 事件过滤器, 返回True则执行回调函数 +Returns: + 装饰器,装饰一个函数在接收到数据后执行 + +### ***def*** `decorator(func: Any) -> None` + + + +### ***def*** `on_modified(self: Any, event: Any) -> None` + + + +### ***def*** `on_created(self: Any, event: Any) -> None` + + + +### ***def*** `on_deleted(self: Any, event: Any) -> None` + + + +### ***def*** `on_moved(self: Any, event: Any) -> None` + + + +### ***def*** `on_any_event(self: Any, event: Any) -> None` + + + +### ***def*** `decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC` + + + +### ***def*** `wrapper() -> None` + + + +### ***def*** `wrapper(event: FileSystemEvent) -> None` + + + +### ***class*** `CodeModifiedHandler(FileSystemEventHandler)` + +Handler for code file changes + +####   ***def*** `on_modified(self: Any, event: Any) -> None` + + + +####   ***def*** `on_created(self: Any, event: Any) -> None` + + + +####   ***def*** `on_deleted(self: Any, event: Any) -> None` + + + +####   ***def*** `on_moved(self: Any, event: Any) -> None` + + + +####   ***def*** `on_any_event(self: Any, event: Any) -> None` + + + diff --git a/docs/en/dev/api/liteyuki/dev/plugin.md b/docs/en/dev/api/liteyuki/dev/plugin.md new file mode 100644 index 00000000..40f118f5 --- /dev/null +++ b/docs/en/dev/api/liteyuki/dev/plugin.md @@ -0,0 +1,13 @@ +--- +title: liteyuki.dev.plugin +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `run_plugins() -> None` + +运行插件,无需手动初始化bot +Args: + module_path: 插件路径,参考`liteyuki.load_plugin`的函数签名 + diff --git a/docs/en/dev/api/liteyuki/exception.md b/docs/en/dev/api/liteyuki/exception.md new file mode 100644 index 00000000..469c00d6 --- /dev/null +++ b/docs/en/dev/api/liteyuki/exception.md @@ -0,0 +1,11 @@ +--- +title: liteyuki.exception +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `LiteyukiException(BaseException)` + +Liteyuki的异常基类。 + diff --git a/docs/en/dev/api/liteyuki/log.md b/docs/en/dev/api/liteyuki/log.md new file mode 100644 index 00000000..30812a21 --- /dev/null +++ b/docs/en/dev/api/liteyuki/log.md @@ -0,0 +1,16 @@ +--- +title: liteyuki.log +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `get_format(level: str) -> str` + + + +### ***def*** `init_log(config: dict) -> None` + +在语言加载完成后执行 +Returns: + diff --git a/docs/en/dev/api/liteyuki/plugin/README.md b/docs/en/dev/api/liteyuki/plugin/README.md new file mode 100644 index 00000000..aa484ffd --- /dev/null +++ b/docs/en/dev/api/liteyuki/plugin/README.md @@ -0,0 +1,13 @@ +--- +title: liteyuki.plugin +index: true +icon: laptop-code +category: API +--- + +### ***def*** `get_loaded_plugins() -> dict[str, Plugin]` + +获取已加载的插件 +Returns: + dict[str, Plugin]: 插件字典 + diff --git a/docs/en/dev/api/liteyuki/plugin/load.md b/docs/en/dev/api/liteyuki/plugin/load.md new file mode 100644 index 00000000..465bf82d --- /dev/null +++ b/docs/en/dev/api/liteyuki/plugin/load.md @@ -0,0 +1,33 @@ +--- +title: liteyuki.plugin.load +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `load_plugin(module_path: str | Path) -> Optional[Plugin]` + +加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。 + +参数: + module_path: 插件名称 `path.to.your.plugin` + 或插件路径 `pathlib.Path(path/to/your/plugin)` + +### ***def*** `load_plugins() -> set[Plugin]` + +导入文件夹下多个插件 + +参数: + plugin_dir: 文件夹路径 + ignore_warning: 是否忽略警告,通常是目录不存在或目录为空 + +### ***def*** `format_display_name(display_name: str, plugin_type: PluginType) -> str` + +设置插件名称颜色,根据不同类型插件设置颜色 +Args: + display_name: 插件名称 + plugin_type: 插件类型 + +Returns: + str: 设置后的插件名称 name + diff --git a/docs/en/dev/api/liteyuki/plugin/manager.md b/docs/en/dev/api/liteyuki/plugin/manager.md new file mode 100644 index 00000000..7d4d951c --- /dev/null +++ b/docs/en/dev/api/liteyuki/plugin/manager.md @@ -0,0 +1,7 @@ +--- +title: liteyuki.plugin.manager +order: 1 +icon: laptop-code +category: API +--- + diff --git a/docs/en/dev/api/liteyuki/plugin/model.md b/docs/en/dev/api/liteyuki/plugin/model.md new file mode 100644 index 00000000..1f17b2d3 --- /dev/null +++ b/docs/en/dev/api/liteyuki/plugin/model.md @@ -0,0 +1,60 @@ +--- +title: liteyuki.plugin.model +order: 1 +icon: laptop-code +category: API +--- + +### ***class*** `PluginType(Enum)` + +插件类型枚举值 + +####   ***attr*** `APPLICATION` + + Type: 'application' + +####   ***attr*** `SERVICE` + + Type: 'service' + +####   ***attr*** `IMPLEMENTATION` + + Type: 'implementation' + +####   ***attr*** `MODULE` + + Type: 'module' + +####   ***attr*** `UNCLASSIFIED` + + Type: 'unclassified' + +### ***class*** `PluginMetadata(BaseModel)` + +轻雪插件元数据,由插件编写者提供,name为必填项 +Attributes: +---------- + +name: str + 插件名称 +description: str + 插件描述 +usage: str + 插件使用方法 +type: str + 插件类型 +author: str + 插件作者 +homepage: str + 插件主页 +extra: dict[str, Any] + 额外信息 + +### ***class*** `Plugin(BaseModel)` + +存储插件信息 + +####   ***attr*** `model_config` + + Type: {'arbitrary_types_allowed': True} + diff --git a/docs/en/dev/api/liteyuki/utils.md b/docs/en/dev/api/liteyuki/utils.md new file mode 100644 index 00000000..e8767e15 --- /dev/null +++ b/docs/en/dev/api/liteyuki/utils.md @@ -0,0 +1,43 @@ +--- +title: liteyuki.utils +order: 1 +icon: laptop-code +category: API +--- + +### ***def*** `is_coroutine_callable(call: Callable[..., Any]) -> bool` + +判断是否为协程可调用对象 +Args: + call: 可调用对象 +Returns: + bool: 是否为协程可调用对象 + +### ***def*** `run_coroutine() -> None` + +运行协程 +Args: + coro: + +Returns: + +### ***def*** `path_to_module_name(path: Path) -> str` + +转换路径为模块名 +Args: + path: 路径a/b/c/d -> a.b.c.d +Returns: + str: 模块名 + +### ***def*** `async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]` + +异步包装器 +Args: + func: Sync Callable +Returns: + Coroutine: Asynchronous Callable + +### ***async def*** `wrapper() -> None` + + + diff --git a/liteyuki/bot/lifespan.py b/liteyuki/bot/lifespan.py index a8c427b2..3df28e93 100644 --- a/liteyuki/bot/lifespan.py +++ b/liteyuki/bot/lifespan.py @@ -42,7 +42,7 @@ class Lifespan: self._after_nonebot_init_funcs: list[LIFESPAN_FUNC] = [] @staticmethod - def _run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None: + def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None: """ 运行函数 Args: @@ -149,7 +149,7 @@ class Lifespan: Returns: """ logger.debug("Running before_start functions") - self._run_funcs(self._before_start_funcs) + self.run_funcs(self._before_start_funcs) def after_start(self) -> None: """ @@ -157,7 +157,7 @@ class Lifespan: Returns: """ logger.debug("Running after_start functions") - self._run_funcs(self._after_start_funcs) + self.run_funcs(self._after_start_funcs) def before_process_shutdown(self) -> None: """ @@ -165,7 +165,7 @@ class Lifespan: Returns: """ logger.debug("Running before_shutdown functions") - self._run_funcs(self._before_process_shutdown_funcs) + self.run_funcs(self._before_process_shutdown_funcs) def after_shutdown(self) -> None: """ @@ -173,7 +173,7 @@ class Lifespan: Returns: """ logger.debug("Running after_shutdown functions") - self._run_funcs(self._after_shutdown_funcs) + self.run_funcs(self._after_shutdown_funcs) def before_process_restart(self) -> None: """ @@ -181,7 +181,7 @@ class Lifespan: Returns: """ logger.debug("Running before_restart functions") - self._run_funcs(self._before_process_restart_funcs) + self.run_funcs(self._before_process_restart_funcs) def after_restart(self) -> None: """ @@ -190,4 +190,4 @@ class Lifespan: """ logger.debug("Running after_restart functions") - self._run_funcs(self._after_restart_funcs) + self.run_funcs(self._after_restart_funcs)