MCPcopy
hub / github.com/nonebot/nonebot2 / on

Function on

nonebot/plugin/on.py:114–153  ·  view source on GitHub ↗

注册一个基础事件响应器,可自定义类型。 参数: type: 事件响应器类型 rule: 事件响应规则 permission: 事件响应权限 handlers: 事件处理函数列表 temp: 是否为临时事件响应器(仅执行一次) expire_time: 事件响应器最终有效时间点,过时即被删除 priority: 事件响应器优先级 block: 是否阻止事件向更低优先级传递 state: 默认 state

(
    type: str = "",
    rule: Rule | T_RuleChecker | None = None,
    permission: Permission | T_PermissionChecker | None = None,
    *,
    handlers: list[T_Handler | Dependent[Any]] | None = None,
    temp: bool = False,
    expire_time: datetime | timedelta | None = None,
    priority: int = 1,
    block: bool = False,
    state: T_State | None = None,
    _depth: int = 0,
)

Source from the content-addressed store, hash-verified

112
113
114def on(
115 type: str = "",
116 rule: Rule | T_RuleChecker | None = None,
117 permission: Permission | T_PermissionChecker | None = None,
118 *,
119 handlers: list[T_Handler | Dependent[Any]] | None = None,
120 temp: bool = False,
121 expire_time: datetime | timedelta | None = None,
122 priority: int = 1,
123 block: bool = False,
124 state: T_State | None = None,
125 _depth: int = 0,
126) -> type[Matcher]:
127 """注册一个基础事件响应器,可自定义类型。
128
129 参数:
130 type: 事件响应器类型
131 rule: 事件响应规则
132 permission: 事件响应权限
133 handlers: 事件处理函数列表
134 temp: 是否为临时事件响应器(仅执行一次)
135 expire_time: 事件响应器最终有效时间点,过时即被删除
136 priority: 事件响应器优先级
137 block: 是否阻止事件向更低优先级传递
138 state: 默认 state
139 """
140 matcher = Matcher.new(
141 type,
142 Rule() & rule,
143 Permission() | permission,
144 temp=temp,
145 expire_time=expire_time,
146 priority=priority,
147 block=block,
148 handlers=handlers,
149 source=get_matcher_source(_depth + 1),
150 default_state=state,
151 )
152 store_matcher(matcher)
153 return matcher
154
155
156def on_metaevent(*args, _depth: int = 0, **kwargs) -> type[Matcher]:

Callers 9

matcher_info.pyFile · 0.90
matchers.pyFile · 0.90
matcher_on_factoryFunction · 0.90
on_metaeventFunction · 0.85
on_messageFunction · 0.85
on_noticeFunction · 0.85
on_requestFunction · 0.85
on_typeFunction · 0.85
onMethod · 0.85

Calls 5

RuleClass · 0.90
PermissionClass · 0.90
get_matcher_sourceFunction · 0.85
store_matcherFunction · 0.85
newMethod · 0.80

Tested by

no test coverage detected