Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
⬆️ version 0.6.0
Browse files Browse the repository at this point in the history
resolve #5
  • Loading branch information
RF-Tar-Railt committed May 26, 2023
1 parent 75a5dd1 commit 1781bb4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
20 changes: 10 additions & 10 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "nonebot-plugin-alconna"
version = "0.5.1"
version = "0.6.0"
description = "Alconna Adapter for Nonebot"
authors = [
{name = "RF-Tar-Railt", email = "[email protected]"},
]
dependencies = [
"nonebot2>=2.0.0rc4",
"arclet-alconna<2.0.0, >=1.7.6",
"arclet-alconna<2.0.0, >=1.7.7",
"arclet-alconna-tools<0.7.0, >=0.6.0",
]
requires-python = ">=3.8"
Expand Down
3 changes: 2 additions & 1 deletion src/nonebot_plugin_alconna/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Generic, TypeVar, Optional, TypedDict
from typing_extensions import NotRequired

from arclet.alconna import Arparma, Empty
from arclet.alconna import Arparma, Empty, Alconna
from arclet.alconna.duplication import Duplication

T = TypeVar("T")
Expand Down Expand Up @@ -46,6 +46,7 @@ def __repr__(self):

@dataclass(frozen=True)
class CommandResult:
source: Alconna
result: Arparma
output: Optional[str] = field(default=None)

Expand Down
7 changes: 4 additions & 3 deletions src/nonebot_plugin_alconna/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing_extensions import Annotated

from arclet.alconna import Arparma, Duplication, Empty
from arclet.alconna.duplication import generate_duplication
from arclet.alconna.builtin import generate_duplication
from nonebot.internal.matcher import Matcher as Matcher
from nonebot.internal.params import Depends as Depends
from nonebot.typing import T_State
Expand Down Expand Up @@ -66,8 +66,9 @@ def AlconnaDuplication(__t: Type[T_Duplication]) -> T_Duplication:

def AlconnaDuplication(__t: Optional[Type[T_Duplication]] = None) -> Duplication:
def _alconna_match(state: T_State) -> Duplication:
arp = _alconna_result(state).result
return __t(arp) if __t else generate_duplication(arp)
res = _alconna_result(state)
gt = __t or generate_duplication(res.source)
return gt(res.result)

return Depends(_alconna_match, use_cache=False)

Expand Down
6 changes: 4 additions & 2 deletions src/nonebot_plugin_alconna/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ async def __call__(self, event: Event, state: T_State, bot: Bot) -> bool:
try:
arp = await self.handle(bot, event, msg)
except Exception as e:
arp = Arparma(self.command.path, msg, False, error_info=repr(e))
arp = Arparma(self.command.path, msg, False, error_info=e)
may_help_text: Optional[str] = cap.get("output", None)
if not arp.matched and not may_help_text and self.skip:
return False
if not may_help_text and arp.error_info:
may_help_text = repr(arp.error_info)
if self.auto_send and may_help_text:
await bot.send(event, await self._convert(may_help_text, event, arp))
return False
state[ALCONNA_RESULT] = CommandResult(arp, may_help_text)
state[ALCONNA_RESULT] = CommandResult(self.command, arp, may_help_text)
return True

async def _convert(self, text: str, event: Event, arp: Arparma) -> Message:
Expand Down

0 comments on commit 1781bb4

Please sign in to comment.