MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / IsTypeRule

Class IsTypeRule

nonebot/rule.py:744–762  ·  view source on GitHub ↗

检查事件类型是否为指定类型。

Source from the content-addressed store, hash-verified

742
743
744class IsTypeRule:
745 """检查事件类型是否为指定类型。"""
746
747 __slots__ = ("types",)
748
749 def __init__(self, *types: type[Event]):
750 self.types = types
751
752 def __repr__(self) -> str:
753 return f"IsType(types={tuple(type.__name__ for type in self.types)})"
754
755 def __eq__(self, other: object) -> bool:
756 return isinstance(other, IsTypeRule) and self.types == other.types
757
758 def __hash__(self) -> int:
759 return hash((self.types,))
760
761 async def __call__(self, event: Event) -> bool:
762 return isinstance(event, self.types)
763
764
765def is_type(*types: type[Event]) -> Rule:

Callers 1

is_typeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected