using set for rule and perm

This commit is contained in:
yanyongyu 2020-09-13 22:36:40 +08:00
parent b36acc94f1
commit 75df494de2
2 changed files with 15 additions and 5 deletions

View File

@ -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)

View File

@ -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)