mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-17 03:20:54 +00:00
✨ finish typing change
This commit is contained in:
@ -13,18 +13,18 @@ from nonebot.log import logger
|
||||
from nonebot.rule import TrieRule
|
||||
from nonebot.matcher import matchers, Matcher
|
||||
from nonebot.exception import IgnoredException, StopPropagation, NoLogException
|
||||
from nonebot.typing import State, EventPreProcessor, RunPreProcessor, EventPostProcessor, RunPostProcessor
|
||||
from nonebot.typing import T_State, T_EventPreProcessor, T_RunPreProcessor, T_EventPostProcessor, T_RunPostProcessor
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot.adapters import Bot, Event
|
||||
|
||||
_event_preprocessors: Set[EventPreProcessor] = set()
|
||||
_event_postprocessors: Set[EventPostProcessor] = set()
|
||||
_run_preprocessors: Set[RunPreProcessor] = set()
|
||||
_run_postprocessors: Set[RunPostProcessor] = set()
|
||||
_event_preprocessors: Set[T_EventPreProcessor] = set()
|
||||
_event_postprocessors: Set[T_EventPostProcessor] = set()
|
||||
_run_preprocessors: Set[T_RunPreProcessor] = set()
|
||||
_run_postprocessors: Set[T_RunPostProcessor] = set()
|
||||
|
||||
|
||||
def event_preprocessor(func: EventPreProcessor) -> EventPreProcessor:
|
||||
def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -36,13 +36,13 @@ def event_preprocessor(func: EventPreProcessor) -> EventPreProcessor:
|
||||
|
||||
* ``bot: Bot``: Bot 对象
|
||||
* ``event: Event``: Event 对象
|
||||
* ``state: State``: 当前 State
|
||||
* ``state: T_State``: 当前 State
|
||||
"""
|
||||
_event_preprocessors.add(func)
|
||||
return func
|
||||
|
||||
|
||||
def event_postprocessor(func: EventPostProcessor) -> EventPostProcessor:
|
||||
def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -54,13 +54,13 @@ def event_postprocessor(func: EventPostProcessor) -> EventPostProcessor:
|
||||
|
||||
* ``bot: Bot``: Bot 对象
|
||||
* ``event: Event``: Event 对象
|
||||
* ``state: State``: 当前事件运行前 State
|
||||
* ``state: T_State``: 当前事件运行前 State
|
||||
"""
|
||||
_event_postprocessors.add(func)
|
||||
return func
|
||||
|
||||
|
||||
def run_preprocessor(func: RunPreProcessor) -> RunPreProcessor:
|
||||
def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -73,13 +73,13 @@ def run_preprocessor(func: RunPreProcessor) -> RunPreProcessor:
|
||||
* ``matcher: Matcher``: 当前要运行的事件响应器
|
||||
* ``bot: Bot``: Bot 对象
|
||||
* ``event: Event``: Event 对象
|
||||
* ``state: State``: 当前 State
|
||||
* ``state: T_State``: 当前 State
|
||||
"""
|
||||
_run_preprocessors.add(func)
|
||||
return func
|
||||
|
||||
|
||||
def run_postprocessor(func: RunPostProcessor) -> RunPostProcessor:
|
||||
def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -93,18 +93,18 @@ def run_postprocessor(func: RunPostProcessor) -> RunPostProcessor:
|
||||
* ``exception: Optional[Exception]``: 事件响应器运行错误(如果存在)
|
||||
* ``bot: Bot``: Bot 对象
|
||||
* ``event: Event``: Event 对象
|
||||
* ``state: State``: 当前 State
|
||||
* ``state: T_State``: 当前 State
|
||||
"""
|
||||
_run_postprocessors.add(func)
|
||||
return func
|
||||
|
||||
|
||||
async def _check_matcher(priority: int, bot: "Bot", event: "Event",
|
||||
state: State) -> Iterable[Type[Matcher]]:
|
||||
state: T_State) -> Iterable[Type[Matcher]]:
|
||||
current_matchers = matchers[priority].copy()
|
||||
|
||||
async def _check(Matcher: Type[Matcher], bot: "Bot", event: "Event",
|
||||
state: State) -> Optional[Type[Matcher]]:
|
||||
state: T_State) -> Optional[Type[Matcher]]:
|
||||
try:
|
||||
if (not Matcher.expire_time or datetime.now() <= Matcher.expire_time
|
||||
) and await Matcher.check_perm(
|
||||
@ -139,7 +139,7 @@ async def _check_matcher(priority: int, bot: "Bot", event: "Event",
|
||||
|
||||
|
||||
async def _run_matcher(Matcher: Type[Matcher], bot: "Bot", event: "Event",
|
||||
state: State) -> None:
|
||||
state: T_State) -> None:
|
||||
logger.info(f"Event will be handled by {Matcher}")
|
||||
|
||||
matcher = Matcher()
|
||||
|
Reference in New Issue
Block a user