def on_endswith( msg: Union[str, Tuple[str, ...]], rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = None, ignorecase: bool = False, _depth: int = 0, **kwargs, ) -> Type[Matcher]: """ :说明: 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。 :参数: * ``msg: Union[str, Tuple[str, ...]]``: 指定消息结尾内容 * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 * ``ignorecase: bool``: 是否忽略大小写 * ``permission: Optional[Union[Permission, T_PermissionChecker]] =]]``: 事件响应权限 * ``handlers: Optional[List[Union[T_Handler, Dependent]]]``: 事件处理函数列表 * ``temp: bool``: 是否为临时事件响应器(仅执行一次) * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state :返回: - ``Type[Matcher]`` """ return on_message(endswith(msg, ignorecase) & rule, **kwargs, _depth=_depth + 1)
def on_endswith(msg: str, rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = None, **kwargs) -> Type[Matcher]: """ :说明: 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。 :参数: * ``msg: str``: 指定消息结尾内容 * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 * ``permission: Optional[Permission]``: 事件响应权限 * ``handlers: Optional[List[T_Handler]]``: 事件处理函数列表 * ``temp: bool``: 是否为临时事件响应器(仅执行一次) * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: - ``Type[Matcher]`` """ return on_message(endswith(msg) & rule, **kwargs)
def on_endswith(msg: str, rule: Optional[Union[Rule, RuleChecker]] = None, permission: Permission = Permission(), **kwargs) -> Type[Matcher]: return on_message(endswith(msg) & rule, permission, **kwargs) if rule else on_message( startswith(msg), permission, **kwargs)
async def test_endswith( app: App, msg: Union[str, Tuple[str, ...]], ignorecase: bool, type: str, text: str, expected: bool, ): from nonebot.rule import EndswithRule, endswith test_endswith = endswith(msg, ignorecase) dependent = list(test_endswith.checkers)[0] checker = dependent.call assert isinstance(checker, EndswithRule) assert checker.msg == (msg, ) if isinstance(msg, str) else msg assert checker.ignorecase == ignorecase message = make_fake_message()(text) event = make_fake_event(_type=type, _message=message)() assert await dependent(event=event) == expected
def on_endswith( msg: Union[str, Tuple[str, ...]], rule: Optional[Union[Rule, T_RuleChecker]] = None, ignorecase: bool = False, _depth: int = 0, **kwargs, ) -> Type[Matcher]: """ 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。 参数: msg: 指定消息结尾内容 rule: 事件响应规则 ignorecase: 是否忽略大小写 permission: 事件响应权限 handlers: 事件处理函数列表 temp: 是否为临时事件响应器(仅执行一次) priority: 事件响应器优先级 block: 是否阻止事件向更低优先级传递 state: 默认 state """ return on_message(endswith(msg, ignorecase) & rule, **kwargs, _depth=_depth + 1)