令返回符合格式

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

@ -45,10 +45,6 @@ class Export(dict):
def export() -> Export:
"""
获取插件的导出内容对象
:返回:
- `Export`
"""
plugin = _current_plugin.get()
if not plugin:

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`: 插件无法加载
"""

View File

@ -66,10 +66,6 @@ def on(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
matcher = Matcher.new(
type,
@ -107,10 +103,6 @@ def on_metaevent(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
matcher = Matcher.new(
"meta_event",
@ -150,10 +142,6 @@ def on_message(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
matcher = Matcher.new(
"message",
@ -191,10 +179,6 @@ def on_notice(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
matcher = Matcher.new(
"notice",
@ -232,10 +216,6 @@ def on_request(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
matcher = Matcher.new(
"request",
@ -273,10 +253,6 @@ def on_startswith(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
return on_message(startswith(msg, ignorecase) & rule, **kwargs, _depth=_depth + 1)
@ -301,10 +277,6 @@ def on_endswith(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
return on_message(endswith(msg, ignorecase) & rule, **kwargs, _depth=_depth + 1)
@ -327,10 +299,6 @@ def on_keyword(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
return on_message(keyword(*keywords) & rule, **kwargs, _depth=_depth + 1)
@ -357,10 +325,6 @@ def on_command(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
commands = set([cmd]) | (aliases or set())
@ -396,10 +360,6 @@ def on_shell_command(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
commands = set([cmd]) | (aliases or set())
@ -432,10 +392,6 @@ def on_regex(
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
return on_message(regex(pattern, flags) & rule, **kwargs, _depth=_depth + 1)
@ -467,10 +423,6 @@ class CommandGroup:
参数:
cmd: 命令前缀
**kwargs`on_command` 的参数,将会覆盖命令组默认值
:返回:
- `Type[Matcher]`
"""
sub_cmd = (cmd,) if isinstance(cmd, str) else cmd
cmd = self.basecmd + sub_cmd
@ -488,10 +440,6 @@ class CommandGroup:
参数:
cmd: 命令前缀
**kwargs`on_shell_command` 的参数,将会覆盖命令组默认值
:返回:
- `Type[Matcher]`
"""
sub_cmd = (cmd,) if isinstance(cmd, str) else cmd
cmd = self.basecmd + sub_cmd
@ -530,10 +478,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -552,10 +496,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -577,10 +517,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -600,10 +536,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -623,10 +555,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -651,10 +579,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -677,10 +601,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -702,10 +622,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -735,10 +651,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -772,10 +684,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)
@ -804,10 +712,6 @@ class MatcherGroup:
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
:返回:
- `Type[Matcher]`
"""
final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs)

View File

@ -58,10 +58,6 @@ def get_plugin(name: str) -> Optional[Plugin]:
参数:
name: 插件名,与 `load_plugin` 参数一致。如果为 `load_plugins` 导入的插件,则为文件(夹)名。
:返回:
- `Optional[Plugin]`
"""
return plugins.get(name)
@ -69,10 +65,6 @@ def get_plugin(name: str) -> Optional[Plugin]:
def get_loaded_plugins() -> Set[Plugin]:
"""
获取当前已导入的所有插件。
:返回:
- `Set[Plugin]`
"""
return set(plugins.values())