Skip to content

Commit 062177f

Browse files
committed
update 0.18.4
1 parent 2a54f12 commit 062177f

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

poetry.lock

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "graia-application-mirai"
3-
version = "0.18.3"
3+
version = "0.18.4"
44
description = ""
55
authors = ["GreyElaina <GreyElaina@outlook.com>"]
66
license = "AGPL-3.0"

src/graia/application/message/parser/kanata.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from graia.broadcast.entities.signatures import Force
77
from graia.broadcast.exceptions import ExecutionStop
88
from graia.broadcast.interfaces.dispatcher import DispatcherInterface
9+
from graia.broadcast.builtin.factory import (
10+
AsyncDispatcherContextManager,
11+
ResponseCodeEnum,
12+
StatusCodeEnum,
13+
)
914

1015
from graia.application.exceptions import ConflictItem
1116

@@ -43,7 +48,7 @@ def origin_or_zero(origin: Optional[_T]) -> Union[_T, int]:
4348
return origin
4449

4550

46-
class Kanata(BaseDispatcher):
51+
class Kanata(AsyncDispatcherContextManager):
4752
"彼方."
4853
signature_list: List[Union[NormalMatch, PatternReceiver]]
4954
stop_exec_if_fail: bool = True
@@ -53,6 +58,9 @@ class Kanata(BaseDispatcher):
5358
allow_quote: bool
5459
skip_one_at_in_quote: bool
5560

61+
args = ()
62+
kwargs = {}
63+
5664
def __init__(
5765
self,
5866
signature_list: List[Union[NormalMatch, PatternReceiver]],
@@ -290,7 +298,10 @@ def allocation(
290298
async def catch_argument_names(self) -> List[str]:
291299
return [i.name for i in self.signature_list if isinstance(i, PatternReceiver)]
292300

293-
async def beforeDispatch(self, interface: DispatcherInterface):
301+
async def generator_factory(self):
302+
interface: DispatcherInterface = (yield)
303+
current_status: StatusCodeEnum = StatusCodeEnum.DISPATCHING # init stat
304+
294305
message_chain: MessageChain = (
295306
await interface.lookup_param("__kanata_messagechain__", MessageChain, None)
296307
).exclude(Source)
@@ -308,27 +319,21 @@ async def beforeDispatch(self, interface: DispatcherInterface):
308319

309320
mapping_result = self.detect_and_mapping(self.signature_list, message_chain)
310321
if mapping_result is not None:
311-
self.parsed_items = self.allocation(mapping_result)
312-
else:
313-
if self.stop_exec_if_fail:
314-
raise ExecutionStop()
315-
316-
async def catch(self, interface: DispatcherInterface):
317-
if interface.name == "__kanata_messagechain__":
318-
return
319-
320-
random_id = random.random()
321-
if self.parsed_items is not None:
322-
result = self.parsed_items.get(interface.name, random_id)
323-
return Force(result) if result is not random_id else None
322+
parsed_items = self.allocation(mapping_result)
324323
else:
325324
if self.stop_exec_if_fail:
326325
raise ExecutionStop()
326+
yield
327+
while current_status is StatusCodeEnum.DISPATCHING:
328+
result = None
329+
330+
if interface.name != "__kanata_messagechain__":
331+
random_id = random.random()
332+
if parsed_items is not None:
333+
item = parsed_items.get(interface.name, random_id)
334+
result = Force(item) if item is not random_id else None
335+
else:
336+
if self.stop_exec_if_fail:
337+
raise ExecutionStop()
327338

328-
async def afterDispatch(
329-
self,
330-
interface: "DispatcherInterface",
331-
exception: Optional[Exception] = None,
332-
tb: Optional[TracebackType] = None,
333-
):
334-
self.parsed_items = None
339+
current_status, external = yield (ResponseCodeEnum.VALUE, result)

src/graia/application/test/request_tracing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def build_session(
5050
trace_config.freeze()
5151

5252
def hook_method(method):
53-
@functools.wraps(method.__func__)
5453
def hooked_wrapper(*args, **kwargs):
5554
return method(*args, **{**kwargs, "trace_request_ctx": (args, kwargs)})
5655

0 commit comments

Comments
 (0)