Skip to content

Commit

Permalink
✨ 添加获取会话状态内容的依赖注入 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
A-kirami committed Sep 5, 2023
1 parent 66fe41e commit 7ee27f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions kirami/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
extract_plain_text,
)

T = TypeVar("T")


class DependsInner(BaseDependsInner):
def __call__(
Expand Down Expand Up @@ -292,13 +294,20 @@ async def client_session() -> AsyncGenerator[AsyncClient, None]:
"""网络连接会话对象"""


def useStateData(key: str | None = None) -> Any:
"""提取会话状态内容"""
return ArgInner(key, type="state") # type: ignore


StateData = Annotated[T, useStateData()]
"""会话状态内容"""


def useArgot(key: str | None = None) -> Any:
"""提取暗语的内容"""
return ArgInner(key, type="argot") # type: ignore


T = TypeVar("T")

Argot = Annotated[T, useArgot()]
"""暗语内容"""

Expand Down
4 changes: 3 additions & 1 deletion kirami/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ def get_plaintext(self: Event) -> str:


async def _solve(self: ArgParam, matcher: Matcher, **_kwargs: Any) -> Any:
"""支持 Argot"""
"""支持 State、Argot 内容提取"""
key: str = self.extra["key"]
if self.extra["type"] == "state":
return matcher.state.get(key)
if self.extra["type"] == "argot":
return matcher.get_argot(key)
message = matcher.get_arg(key)
Expand Down

0 comments on commit 7ee27f1

Please sign in to comment.