mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 06:21:29 +08:00
⚡ improve full match performance with frozenset
This commit is contained in:
parent
f737bb899c
commit
0f0dc0a818
@ -182,20 +182,15 @@ class FullmatchRule:
|
|||||||
__slots__ = ("msg", "ignorecase")
|
__slots__ = ("msg", "ignorecase")
|
||||||
|
|
||||||
def __init__(self, msg: Tuple[str, ...], ignorecase: bool = False):
|
def __init__(self, msg: Tuple[str, ...], ignorecase: bool = False):
|
||||||
self.msg = msg
|
self.msg = frozenset(map(str.casefold, msg) if ignorecase else msg)
|
||||||
self.ignorecase = ignorecase
|
self.ignorecase = ignorecase
|
||||||
|
|
||||||
async def __call__(
|
async def __call__(
|
||||||
self, type: str = EventType(), text: str = EventPlainText()
|
self, type_: str = EventType(), text: str = EventPlainText()
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if type != "message":
|
return (
|
||||||
return False
|
type_ == "message"
|
||||||
return bool(
|
and (text.casefold() if self.ignorecase else text) in self.msg
|
||||||
text
|
|
||||||
and any(
|
|
||||||
full.lower() == text.lower() if self.ignorecase else full == text
|
|
||||||
for full in self.msg
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user