From 75df494de277b3655cc9b0b7c82ad5d1e21fce61 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Sun, 13 Sep 2020 22:36:40 +0800 Subject: [PATCH] :zap: using set for rule and perm --- nonebot/permission.py | 2 +- nonebot/rule.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nonebot/permission.py b/nonebot/permission.py index 9cd104bb..22a2c66b 100644 --- a/nonebot/permission.py +++ b/nonebot/permission.py @@ -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) diff --git a/nonebot/rule.py b/nonebot/rule.py index 3f34f511..d2f33fcf 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -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)