♻️ rewrite adapter abc class

This commit is contained in:
yanyongyu
2021-12-06 22:19:05 +08:00
parent 180aaadda9
commit d80c02ae46
7 changed files with 172 additions and 437 deletions

View File

@ -14,13 +14,12 @@ from contextlib import AsyncExitStack
from typing import (
Any,
Dict,
List,
Type,
Tuple,
Union,
Callable,
NoReturn,
Optional,
Coroutine,
)
from nonebot import params
@ -30,6 +29,13 @@ from nonebot.exception import SkippedException
from nonebot.typing import T_PermissionChecker
async def _run_coro_with_catch(coro: Coroutine[Any, Any, Any]):
try:
return await coro
except SkippedException:
return False
class Permission:
"""
:说明:
@ -100,20 +106,18 @@ class Permission:
return True
results = await asyncio.gather(
*(
checker(
bot=bot,
event=event,
_stack=stack,
_dependency_cache=dependency_cache,
_run_coro_with_catch(
checker(
bot=bot,
event=event,
_stack=stack,
_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.")