mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
⚡ using set for rule and perm
This commit is contained in:
parent
b36acc94f1
commit
75df494de2
@ -30,7 +30,7 @@ class Permission:
|
||||
if isinstance(other, Permission):
|
||||
checkers |= other.checkers
|
||||
elif asyncio.iscoroutinefunction(other):
|
||||
checkers.add(other)
|
||||
checkers.add(other) # type: ignore
|
||||
else:
|
||||
checkers.add(run_sync(other))
|
||||
return Permission(*checkers)
|
||||
|
@ -155,19 +155,29 @@ class TrieRule:
|
||||
|
||||
|
||||
def startswith(msg: str) -> Rule:
|
||||
TrieRule.add_prefix(msg, (msg,))
|
||||
"""
|
||||
:说明:
|
||||
匹配消息开头
|
||||
:参数:
|
||||
* ``msg: str``: 消息开头字符串
|
||||
"""
|
||||
|
||||
async def _startswith(bot: Bot, event: Event, state: dict) -> bool:
|
||||
return msg in state["_prefix"]
|
||||
return event.plain_text.startswith(msg)
|
||||
|
||||
return Rule(_startswith)
|
||||
|
||||
|
||||
def endswith(msg: str) -> Rule:
|
||||
TrieRule.add_suffix(msg, (msg,))
|
||||
"""
|
||||
:说明:
|
||||
匹配消息结尾
|
||||
:参数:
|
||||
* ``msg: str``: 消息结尾字符串
|
||||
"""
|
||||
|
||||
async def _endswith(bot: Bot, event: Event, state: dict) -> bool:
|
||||
return msg in state["_suffix"]
|
||||
return event.plain_text.endswith(msg)
|
||||
|
||||
return Rule(_endswith)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user