nonebot2/website/versioned_docs/version-2.0.0-beta.5/api/params.md
github-actions[bot] e5e69c2726 🔖 Release 2.0.0-beta.5
2022-08-04 06:27:40 +00:00

4.5 KiB

sidebar_position description
4 nonebot.params 模块

nonebot.params

本模块定义了依赖注入的各类参数。

def Arg(key=None)

  • 说明

    got 的 Arg 参数消息

  • 参数

    • key (str | None)
  • 返回

    • Any

def State()

  • 说明

    Deprecated: 事件处理状态参数,请直接使用 T_State

  • 返回

    • dict[Any, Any]

def ArgStr(key=None)

  • 说明

    got 的 Arg 参数消息文本

  • 参数

    • key (str | None)
  • 返回

    • str

def Depends(dependency=None, *, use_cache=True)

  • 说明

    子依赖装饰器

  • 参数

    • dependency ((*Any, **Any) -> Any | None): 依赖函数。默认为参数的类型注释。

    • use_cache (bool): 是否使用缓存。默认为 True

  • 返回

    • Any
  • 用法

    def depend_func() -> Any:
        return ...
    
    def depend_gen_func():
        try:
            yield ...
        finally:
            ...
    
    async def handler(param_name: Any = Depends(depend_func), gen: Any = Depends(depend_gen_func)):
        ...
    

class ArgParam(default=PydanticUndefined, **kwargs)

  • 说明

    got 的 Arg 参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class BotParam(default=PydanticUndefined, **kwargs)

  • 说明

    Bot 参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class EventParam(default=PydanticUndefined, **kwargs)

  • 说明

    Event 参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class StateParam(default=PydanticUndefined, **kwargs)

  • 说明

    事件处理状态参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class DependParam(default=PydanticUndefined, **kwargs)

  • 说明

    子依赖参数

  • 参数

    • default (Any)

    • **kwargs (Any)

def ArgPlainText(key=None)

  • 说明

    got 的 Arg 参数消息纯文本

  • 参数

    • key (str | None)
  • 返回

    • str

class DefaultParam(default=PydanticUndefined, **kwargs)

  • 说明

    默认值参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class MatcherParam(default=PydanticUndefined, **kwargs)

  • 说明

    事件响应器实例参数

  • 参数

    • default (Any)

    • **kwargs (Any)

class ExceptionParam(default=PydanticUndefined, **kwargs)

  • 说明

    run_postprocessor 的异常参数

  • 参数

    • default (Any)

    • **kwargs (Any)

def EventType()

  • 说明

    Event 类型参数

  • 返回

    • str

def EventMessage()

  • 说明

    Event 消息参数

  • 返回

    • Any

def EventPlainText()

  • 说明

    Event 纯文本消息参数

  • 返回

    • str

def EventToMe()

  • 说明

    Event to_me 参数

  • 返回

    • bool

def Command()

  • 说明

    消息命令元组

  • 返回

    • tuple[str, ...]

def RawCommand()

  • 说明

    消息命令文本

  • 返回

    • str

def CommandArg()

  • 说明

    消息命令参数

  • 返回

    • Any

def CommandStart()

  • 说明

    消息命令开头

  • 返回

    • str

def ShellCommandArgs()

  • 说明

    shell 命令解析后的参数字典

  • 返回

    • Unknown

def ShellCommandArgv()

  • 说明

    shell 命令原始参数列表

  • 返回

    • Any

def RegexMatched()

  • 说明

    正则匹配结果

  • 返回

    • str

def RegexGroup()

  • 说明

    正则匹配结果 group 元组

  • 返回

    • tuple[Any, ...]

def RegexDict()

  • 说明

    正则匹配结果 group 字典

  • 返回

    • dict[str, Any]

def Received(id=None, default=None)

  • 说明

    receive 事件参数

  • 参数

    • id (str | None)

    • default (Any)

  • 返回

    • Any

def LastReceived(default=None)

  • 说明

    last_receive 事件参数

  • 参数

    • default (Any)
  • 返回

    • Any