mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-16 02:50:48 +00:00
调整缩进
This commit is contained in:
@ -213,20 +213,20 @@ class Matcher(metaclass=MatcherMeta):
|
||||
创建一个新的事件响应器,并存储至 `matchers <#matchers>`_
|
||||
|
||||
参数:
|
||||
type_: 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
|
||||
rule: 匹配规则
|
||||
permission: 权限
|
||||
handlers: 事件处理函数列表
|
||||
temp: 是否为临时事件响应器,即触发一次后删除
|
||||
priority: 响应优先级
|
||||
block: 是否阻止事件向更低优先级的响应器传播
|
||||
plugin: 事件响应器所在插件
|
||||
module: 事件响应器所在模块
|
||||
default_state: 默认状态 `state`
|
||||
expire_time: 事件响应器最终有效时间点,过时即被删除
|
||||
type_: 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
|
||||
rule: 匹配规则
|
||||
permission: 权限
|
||||
handlers: 事件处理函数列表
|
||||
temp: 是否为临时事件响应器,即触发一次后删除
|
||||
priority: 响应优先级
|
||||
block: 是否阻止事件向更低优先级的响应器传播
|
||||
plugin: 事件响应器所在插件
|
||||
module: 事件响应器所在模块
|
||||
default_state: 默认状态 `state`
|
||||
expire_time: 事件响应器最终有效时间点,过时即被删除
|
||||
|
||||
返回:
|
||||
Type[Matcher]: 新的事件响应器类
|
||||
Type[Matcher]: 新的事件响应器类
|
||||
"""
|
||||
NewMatcher = type(
|
||||
"Matcher",
|
||||
@ -277,11 +277,11 @@ class Matcher(metaclass=MatcherMeta):
|
||||
检查是否满足触发权限
|
||||
|
||||
参数:
|
||||
bot: Bot 对象
|
||||
event: 上报事件
|
||||
bot: Bot 对象
|
||||
event: 上报事件
|
||||
|
||||
返回:
|
||||
bool: 是否满足权限
|
||||
bool: 是否满足权限
|
||||
"""
|
||||
event_type = event.get_type()
|
||||
return event_type == (cls.type or event_type) and await cls.permission(
|
||||
@ -301,12 +301,12 @@ class Matcher(metaclass=MatcherMeta):
|
||||
检查是否满足匹配规则
|
||||
|
||||
参数:
|
||||
bot: Bot 对象
|
||||
event: 上报事件
|
||||
state: 当前状态
|
||||
bot: Bot 对象
|
||||
event: 上报事件
|
||||
state: 当前状态
|
||||
|
||||
返回:
|
||||
bool: 是否满足匹配规则
|
||||
bool: 是否满足匹配规则
|
||||
"""
|
||||
event_type = event.get_type()
|
||||
return event_type == (cls.type or event_type) and await cls.rule(
|
||||
@ -319,7 +319,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
|
||||
|
||||
参数:
|
||||
func: 响应事件类型更新函数
|
||||
func: 响应事件类型更新函数
|
||||
"""
|
||||
cls._default_type_updater = Dependent[str].parse(
|
||||
call=func, allow_types=cls.HANDLER_PARAM_TYPES
|
||||
@ -332,7 +332,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
装饰一个函数来更改当前事件响应器的默认会话权限更新函数
|
||||
|
||||
参数:
|
||||
func: 会话权限更新函数
|
||||
func: 会话权限更新函数
|
||||
"""
|
||||
cls._default_permission_updater = Dependent[Permission].parse(
|
||||
call=func, allow_types=cls.HANDLER_PARAM_TYPES
|
||||
@ -359,7 +359,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
装饰一个函数来向事件响应器直接添加一个处理函数
|
||||
|
||||
参数:
|
||||
parameterless: 非参数类型依赖列表
|
||||
parameterless: 非参数类型依赖列表
|
||||
"""
|
||||
|
||||
def _decorator(func: T_Handler) -> T_Handler:
|
||||
@ -376,8 +376,8 @@ class Matcher(metaclass=MatcherMeta):
|
||||
装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
|
||||
|
||||
参数:
|
||||
id: 消息 ID
|
||||
parameterless: 非参数类型依赖列表
|
||||
id: 消息 ID
|
||||
parameterless: 非参数类型依赖列表
|
||||
"""
|
||||
|
||||
async def _receive(event: Event, matcher: "Matcher") -> Union[None, NoReturn]:
|
||||
@ -412,13 +412,12 @@ class Matcher(metaclass=MatcherMeta):
|
||||
parameterless: Optional[List[Any]] = None,
|
||||
) -> Callable[[T_Handler], T_Handler]:
|
||||
"""
|
||||
装饰一个函数来指示 NoneBot 当要获取的 `key` 不存在时接收用户新的一条消息并经过 `ArgsParser` 处理后再运行该函数,如果 `key` 已存在则直接继续运行
|
||||
装饰一个函数来指示 NoneBot 当要获取的 `key` 不存在时接收用户新的一条消息再运行该函数,如果 `key` 已存在则直接继续运行
|
||||
|
||||
参数:
|
||||
key: 参数名
|
||||
prompt: 在参数不存在时向用户发送的消息
|
||||
args_parser: 可选参数解析函数,空则使用默认解析函数
|
||||
parameterless: 非参数类型依赖列表
|
||||
key: 参数名
|
||||
prompt: 在参数不存在时向用户发送的消息
|
||||
parameterless: 非参数类型依赖列表
|
||||
"""
|
||||
|
||||
async def _key_getter(event: Event, matcher: "Matcher"):
|
||||
@ -458,8 +457,8 @@ class Matcher(metaclass=MatcherMeta):
|
||||
发送一条消息给当前交互用户
|
||||
|
||||
参数:
|
||||
message: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
message: 消息内容
|
||||
**kwargs: `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
bot = current_bot.get()
|
||||
event = current_event.get()
|
||||
@ -480,8 +479,8 @@ class Matcher(metaclass=MatcherMeta):
|
||||
发送一条消息给当前交互用户并结束当前事件响应器
|
||||
|
||||
参数:
|
||||
message: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
message: 消息内容
|
||||
**kwargs: `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
if message is not None:
|
||||
await cls.send(message, **kwargs)
|
||||
@ -497,8 +496,8 @@ class Matcher(metaclass=MatcherMeta):
|
||||
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
|
||||
|
||||
参数:
|
||||
prompt: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
prompt: 消息内容
|
||||
**kwargs`: bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
if prompt is not None:
|
||||
await cls.send(prompt, **kwargs)
|
||||
@ -514,8 +513,8 @@ class Matcher(metaclass=MatcherMeta):
|
||||
最近使用 `got` / `receive` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
参数:
|
||||
prompt: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
prompt: 消息内容
|
||||
**kwargs: `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
if prompt is not None:
|
||||
await cls.send(prompt, **kwargs)
|
||||
@ -532,9 +531,9 @@ class Matcher(metaclass=MatcherMeta):
|
||||
最近使用 `got` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
参数:
|
||||
key: 参数名
|
||||
prompt: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
key: 参数名
|
||||
prompt: 消息内容
|
||||
**kwargs: `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
matcher = current_matcher.get()
|
||||
matcher.set_target(ARG_KEY.format(key=key))
|
||||
@ -553,9 +552,9 @@ class Matcher(metaclass=MatcherMeta):
|
||||
最近使用 `got` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
参数:
|
||||
id: 消息 id
|
||||
prompt: 消息内容
|
||||
**kwargs`bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
id: 消息 id
|
||||
prompt: 消息内容
|
||||
**kwargs: `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
|
||||
"""
|
||||
matcher = current_matcher.get()
|
||||
matcher.set_target(RECEIVE_KEY.format(id=id))
|
||||
|
Reference in New Issue
Block a user