🐛 Fix: Bot Hook 没有捕获跳过异常 (#905)

This commit is contained in:
Ju4tCode
2022-04-04 10:35:14 +08:00
committed by GitHub
parent 494b9c625d
commit 2f3324ce0c
12 changed files with 333 additions and 303 deletions

View File

@ -21,7 +21,6 @@ from typing import (
TypeVar,
Callable,
Optional,
Awaitable,
Coroutine,
AsyncGenerator,
ContextManager,
@ -132,6 +131,17 @@ async def run_sync_ctx_manager(
await run_sync(cm.__exit__)(None, None, None)
async def run_coro_with_catch(
coro: Coroutine[Any, Any, T],
exc: Tuple[Type[Exception], ...],
return_on_err: R = None,
) -> Union[T, R]:
try:
return await coro
except exc:
return return_on_err
def get_name(obj: Any) -> str:
"""获取对象的名称"""
if inspect.isfunction(obj) or inspect.isclass(obj):