🐛 fix rule and permission not handle skip

This commit is contained in:
yanyongyu 2021-12-01 19:21:31 +08:00
parent a414406039
commit 0236746e65
2 changed files with 21 additions and 13 deletions

View File

@ -16,6 +16,7 @@ from typing import Any, Dict, List, Type, Union, Callable, NoReturn, Optional
from nonebot import params
from nonebot.handler import Handler
from nonebot.adapters import Bot, Event
from nonebot.exception import SkippedException
from nonebot.typing import T_PermissionChecker
@ -96,9 +97,13 @@ class Permission:
_dependency_cache=dependency_cache,
)
for checker in self.checkers
),
return_exceptions=True,
)
return next(
filter(lambda x: bool(x) and not isinstance(x, SkippedException), results),
False,
)
return any(results)
def __and__(self, other) -> NoReturn:
raise RuntimeError("And operation between Permissions is not allowed.")

View File

@ -35,9 +35,9 @@ from pygtrie import CharTrie
from nonebot.log import logger
from nonebot.handler import Handler
from nonebot import params, get_driver
from nonebot.exception import ParserExit
from nonebot.typing import T_State, T_RuleChecker
from nonebot.adapters import Bot, Event, MessageSegment
from nonebot.exception import ParserExit, SkippedException
PREFIX_KEY = "_prefix"
SUFFIX_KEY = "_suffix"
@ -130,6 +130,7 @@ class Rule:
"""
if not self.checkers:
return True
try:
results = await asyncio.gather(
*(
checker(
@ -142,6 +143,8 @@ class Rule:
for checker in self.checkers
)
)
except SkippedException:
return False
return all(results)
def __and__(self, other: Optional[Union["Rule", T_RuleChecker]]) -> "Rule":