mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-06 20:35:45 +00:00
🚨 auto fix by pre-commit hooks
This commit is contained in:
parent
67f5b87492
commit
b3d0e7c548
@ -1,10 +1,8 @@
|
|||||||
from typing import Generator, Dict
|
from typing import Dict, Generator
|
||||||
|
|
||||||
from nonebot.adapters import Event
|
from nonebot.adapters import Event
|
||||||
from nonebot.message import (
|
|
||||||
IgnoredException,
|
|
||||||
event_preprocessor
|
|
||||||
)
|
|
||||||
from nonebot.params import Depends
|
from nonebot.params import Depends
|
||||||
|
from nonebot.message import IgnoredException, event_preprocessor
|
||||||
|
|
||||||
_running_matcher: Dict[str, int] = {}
|
_running_matcher: Dict[str, int] = {}
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ async def matcher_mutex(event: Event) -> Generator[bool, None, None]:
|
|||||||
else:
|
else:
|
||||||
current_event_id = id(event)
|
current_event_id = id(event)
|
||||||
event_id = _running_matcher.get(session_id, None)
|
event_id = _running_matcher.get(session_id, None)
|
||||||
if event_id :
|
if event_id:
|
||||||
result = event_id != current_event_id
|
result = event_id != current_event_id
|
||||||
else:
|
else:
|
||||||
_running_matcher[session_id] = current_event_id
|
_running_matcher[session_id] = current_event_id
|
||||||
@ -26,8 +24,8 @@ async def matcher_mutex(event: Event) -> Generator[bool, None, None]:
|
|||||||
if result:
|
if result:
|
||||||
del _running_matcher[session_id]
|
del _running_matcher[session_id]
|
||||||
|
|
||||||
|
|
||||||
@event_preprocessor
|
@event_preprocessor
|
||||||
async def preprocess(mutex: bool = Depends(matcher_mutex)):
|
async def preprocess(mutex: bool = Depends(matcher_mutex)):
|
||||||
if mutex:
|
if mutex:
|
||||||
raise IgnoredException("Another matcher running")
|
raise IgnoredException("Another matcher running")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user