检查事件类型是否为指定类型。
| 742 | |
| 743 | |
| 744 | class 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 | |
| 765 | def is_type(*types: type[Event]) -> Rule: |