diff --git a/pdm.lock b/pdm.lock index d26843c..96ca245 100644 --- a/pdm.lock +++ b/pdm.lock @@ -19,11 +19,11 @@ dependencies = [ [[package]] name = "arclet-alconna" -version = "1.7.6" +version = "1.7.7" requires_python = ">=3.8" summary = "A High-performance, Generality, Humane Command Line Arguments Parser Library." dependencies = [ - "nepattern<0.6.0,>=0.5.6", + "nepattern<0.6.0,>=0.5.8", "tarina>=0.3.3", "typing-extensions>=4.5.0", ] @@ -154,7 +154,7 @@ summary = "A tiny, secure, URL-friendly, unique string ID generator for Python" [[package]] name = "nepattern" -version = "0.5.6" +version = "0.5.8" requires_python = ">=3.8" summary = "a complex pattern, support typing" dependencies = [ @@ -411,7 +411,7 @@ summary = "Backport of pathlib-compatible object wrapper for zip files" [metadata] lock_version = "4.2" groups = ["default", "dev"] -content_hash = "sha256:21d7ea8a7e942327724bc8a4c00d1372bb213ec57cd01eedce922942736bb8a2" +content_hash = "sha256:51810d842851579d7ddef8b5f9abd43bbde95ef27968b8ef45824c55efeda3df" [metadata.files] "aio-mc-rcon 3.2.0" = [ @@ -422,9 +422,9 @@ content_hash = "sha256:21d7ea8a7e942327724bc8a4c00d1372bb213ec57cd01eedce9229427 {url = "https://files.pythonhosted.org/packages/77/2b/b4c0b7a3f3d61adb1a1e0b78f90a94e2b6162a043880704b7437ef297cad/anyio-3.6.2-py3-none-any.whl", hash = "sha256:fbbe32bd270d2a2ef3ed1c5d45041250284e31fc0a4df4a5a6071842051a51e3"}, {url = "https://files.pythonhosted.org/packages/8b/94/6928d4345f2bc1beecbff03325cad43d320717f51ab74ab5a571324f4f5a/anyio-3.6.2.tar.gz", hash = "sha256:25ea0d673ae30af41a0c442f81cf3b38c7e79fdc7b60335a4c14e05eb0947421"}, ] -"arclet-alconna 1.7.6" = [ - {url = "https://files.pythonhosted.org/packages/52/97/49bf28bf730a6f19718ef38535b10bd0b18a78d1a91788e8e3a6371e5656/arclet-alconna-1.7.6.tar.gz", hash = "sha256:800dd1f0a17f6e81f3a196c9a84170f37ad7b3891c9a448363ac4ffd662dd767"}, - {url = "https://files.pythonhosted.org/packages/e3/cd/4623fa41e939ec947e41eba1d38ee1cc2d2df1920565662085107406f9b3/arclet_alconna-1.7.6-py3-none-any.whl", hash = "sha256:e76990f24eb78ec074611cf093d861f3a6433129cb343796e9319efeb3e66f3f"}, +"arclet-alconna 1.7.7" = [ + {url = "https://files.pythonhosted.org/packages/87/f3/ee4aa593a5e12ade6ebe033ca67a66ffa35a57f93e4efd6d460e29129770/arclet_alconna-1.7.7-py3-none-any.whl", hash = "sha256:46f39cacdf85993ca86e88842b697880a6e4662d40b2c05ccb2909ac39cb0320"}, + {url = "https://files.pythonhosted.org/packages/e0/ee/4d384f1111db814cd91084969f5761e98a6971d33cb6bb6b89995d1bea40/arclet-alconna-1.7.7.tar.gz", hash = "sha256:86c4a6297b005f2ca817e03c02430c2b7da241c856645db56b61a91baa8b14ff"}, ] "arclet-alconna-tools 0.6.0" = [ {url = "https://files.pythonhosted.org/packages/b0/ed/ad6307e2fc0d136f84764cdb490a3fd6148f0221d4465308ea0db6338d23/arclet_alconna_tools-0.6.0-py3-none-any.whl", hash = "sha256:bedbe7c35d41d0e9daba37cf5fbff01e8ac16625a6d48566aacd9f64a07eb5dc"}, @@ -612,9 +612,9 @@ content_hash = "sha256:21d7ea8a7e942327724bc8a4c00d1372bb213ec57cd01eedce9229427 {url = "https://files.pythonhosted.org/packages/2e/0d/8630f13998638dc01e187fadd2e5c6d42d127d08aeb4943d231664d6e539/nanoid-2.0.0-py3-none-any.whl", hash = "sha256:90aefa650e328cffb0893bbd4c236cfd44c48bc1f2d0b525ecc53c3187b653bb"}, {url = "https://files.pythonhosted.org/packages/b7/9d/0250bf5935d88e214df469d35eccc0f6ff7e9db046fc8a9aeb4b2a192775/nanoid-2.0.0.tar.gz", hash = "sha256:5a80cad5e9c6e9ae3a41fa2fb34ae189f7cb420b2a5d8f82bd9d23466e4efa68"}, ] -"nepattern 0.5.6" = [ - {url = "https://files.pythonhosted.org/packages/04/24/02d2086a50be474779a4930b49018c90811efcafb48fd8a2d417b6f8936e/nepattern-0.5.6.tar.gz", hash = "sha256:6c5100cea2a782f0d1780d0e5bc912b6e9151e18e168c463f01a38dc85752291"}, - {url = "https://files.pythonhosted.org/packages/5f/16/4cdb3ce11bb7036c8be0287ebe20c1ddd564cdf66bea5645b4751d417dc2/nepattern-0.5.6-py3-none-any.whl", hash = "sha256:d266fdd8e58c83e2e9940ee86a89e0d0a30495b2ff862a67053528644f7b1c4a"}, +"nepattern 0.5.8" = [ + {url = "https://files.pythonhosted.org/packages/32/5a/2fccd28dcb5dd59a147f4be0e0294b1a25783868d9ac4aa98e7f405c0e5b/nepattern-0.5.8.tar.gz", hash = "sha256:ff1d2579a8d44b83933463c84df4df5c9bf009e0804c5c0d6d325b8e0a29d53e"}, + {url = "https://files.pythonhosted.org/packages/6d/b2/55fb438a5e0ac67d00a134686c6a16cfa2538dcf09314e9b26269d0e4589/nepattern-0.5.8-py3-none-any.whl", hash = "sha256:f4e666f58642536d493303760776944c76ca1396fc5c22187d623d4c12420c89"}, ] "nonebot-adapter-console 0.3.2" = [ {url = "https://files.pythonhosted.org/packages/3a/1a/46176a8f6fe1e89c04ac8c4e358d7e6f43a9a3355b4a41100f48ef650453/nonebot_adapter_console-0.3.2-py3-none-any.whl", hash = "sha256:0467b48482e726833592b1c644a51e3688e0712a71897efed5cdc7b066aee5b2"}, diff --git a/pyproject.toml b/pyproject.toml index 75977c1..b047730 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "rf_tar_railt@qq.com"}, ] 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" diff --git a/src/nonebot_plugin_alconna/model.py b/src/nonebot_plugin_alconna/model.py index 534b84d..8bdfa47 100644 --- a/src/nonebot_plugin_alconna/model.py +++ b/src/nonebot_plugin_alconna/model.py @@ -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") @@ -46,6 +46,7 @@ def __repr__(self): @dataclass(frozen=True) class CommandResult: + source: Alconna result: Arparma output: Optional[str] = field(default=None) diff --git a/src/nonebot_plugin_alconna/params.py b/src/nonebot_plugin_alconna/params.py index 853996c..5ac9bd6 100644 --- a/src/nonebot_plugin_alconna/params.py +++ b/src/nonebot_plugin_alconna/params.py @@ -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 @@ -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) diff --git a/src/nonebot_plugin_alconna/rule.py b/src/nonebot_plugin_alconna/rule.py index 4862d64..49340bf 100644 --- a/src/nonebot_plugin_alconna/rule.py +++ b/src/nonebot_plugin_alconna/rule.py @@ -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: