令返回符合格式

This commit is contained in:
hemengyang
2022-01-12 18:43:07 +08:00
parent 456d333568
commit 187532930b
11 changed files with 20 additions and 232 deletions

View File

@ -16,10 +16,6 @@ def load_plugin(module_path: str) -> Optional[Plugin]:
参数:
module_path: 插件名称 `path.to.your.plugin`
:返回:
- `Optional[Plugin]`
"""
manager = PluginManager([module_path])
@ -32,11 +28,7 @@ def load_plugins(*plugin_dir: str) -> Set[Plugin]:
导入目录下多个插件,以 `_` 开头的插件不会被导入!
参数:
- `*plugin_dir: str`: 插件路径
:返回:
- `Set[Plugin]`
plugin_dir: 插件路径
"""
manager = PluginManager(search_path=plugin_dir)
_managers.append(manager)
@ -50,12 +42,8 @@ def load_all_plugins(
导入指定列表中的插件以及指定目录下多个插件,以 `_` 开头的插件不会被导入!
参数:
- `module_path: Iterable[str]`: 指定插件集合
- `plugin_dir: Iterable[str]`: 指定插件路径集合
:返回:
- `Set[Plugin]`
module_path: 指定插件集合
plugin_dir: 指定插件路径集合
"""
manager = PluginManager(module_path, plugin_dir)
_managers.append(manager)
@ -67,13 +55,8 @@ def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
导入指定 json 文件中的 `plugins` 以及 `plugin_dirs` 下多个插件,以 `_` 开头的插件不会被导入!
参数:
- `file_path: str`: 指定 json 文件路径
- `encoding: str`: 指定 json 文件编码
:返回:
- `Set[Plugin]`
"""
file_path: 指定 json 文件路径
encoding: 指定 json 文件编码"""
with open(file_path, "r", encoding=encoding) as f:
data = json.load(f)
plugins = data.get("plugins")
@ -89,13 +72,8 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
以 `_` 开头的插件不会被导入!
参数:
- `file_path: str`: 指定 toml 文件路径
- `encoding: str`: 指定 toml 文件编码
:返回:
- `Set[Plugin]`
"""
file_path: 指定 toml 文件路径
encoding: 指定 toml 文件编码"""
with open(file_path, "r", encoding=encoding) as f:
data = tomlkit.parse(f.read()) # type: ignore
@ -119,10 +97,6 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
def load_builtin_plugin(name: str) -> Optional[Plugin]:
"""
导入 NoneBot 内置插件
:返回:
- `Plugin`
"""
return load_plugin(f"nonebot.plugins.{name}")
@ -130,10 +104,6 @@ def load_builtin_plugin(name: str) -> Optional[Plugin]:
def load_builtin_plugins(*plugins) -> Set[Plugin]:
"""
导入多个 NoneBot 内置插件
:返回:
- `Set[Plugin]`
"""
return load_all_plugins([f"nonebot.plugins.{p}" for p in plugins], [])
@ -145,10 +115,6 @@ def require(name: str) -> Export:
参数:
name: 插件名,与 `load_plugin` 参数一致。如果为 `load_plugins` 导入的插件,则为文件(夹)名。
:返回:
- `Export`
:异常:
- `RuntimeError`: 插件无法加载
"""