From c7cc25562b46315afd7c79d7d1afb863e9f293cb Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Thu, 26 Dec 2024 09:48:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E9=80=81=E7=9A=84=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=AF=B9=E5=BA=94=E6=8C=87=E4=BB=A4=E7=9A=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=B8=AE=E5=8A=A9=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__init__.py | 22 ++++++++++++++++--- pyproject.toml | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/nonebot_plugin_tsugu_bangdream_bot/__init__.py b/nonebot_plugin_tsugu_bangdream_bot/__init__.py index 0a86b39..3310601 100644 --- a/nonebot_plugin_tsugu_bangdream_bot/__init__.py +++ b/nonebot_plugin_tsugu_bangdream_bot/__init__.py @@ -21,7 +21,7 @@ store_true, command_manager, referent, - on_alconna + on_alconna, ) require("nonebot_plugin_userinfo") @@ -193,14 +193,30 @@ async def _(bot: Bot, event: Event, group: Tuple[Any, ...] = RegexGroup()) -> No if is_forwarded: logger.debug(f"Submitted room number: '{group[0]}'") +# 统一的命令参数预处理,添加帮助指令自动回复 +async def _process_if_unmatch(matcher: AlconnaMatcher, arp: Arparma) -> None: + if not arp.matched: + # 指令参数格式不匹配 + error_msg = ( + str(arp.error_info) + + '\n' + + matcher.command().get_help() + ) + await matcher.finish(error_msg) + else: + matcher.skip() + # 统一的命令 build 方法 def _build(cmd: Command, aliases: Set[str]) -> Type[AlconnaMatcher]: - return cmd.build( - auto_send_output=True, + _matcher = cmd.build( + skip_for_unmatch=False, + auto_send_output=False, aliases=aliases, extensions=[extension], use_cmd_start=True ) + _matcher.handle()(_process_if_unmatch) + return _matcher # 定义 tsugu namespace with namespace("tsugu") as tsugu_namespace: diff --git a/pyproject.toml b/pyproject.toml index 66d13ec..a6c0e1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-plugin-tsugu-bangdream-bot" -version = "0.3.0" +version = "0.4.0" description = "Koishi-Plugin-Tsugu-BanGDream-Bot 的 NoneBot2 实现" authors = [ {name = "WindowsSov8forUs", email = "qwertyuiop2333@hotmail.com"}, @@ -8,7 +8,7 @@ authors = [ dependencies = [ "nonebot2>=2.2.1", "nonebot-plugin-alconna>=0.46.1", - "tsugu-api-python>=1.4.1", + "tsugu-api-python>=1.4.2", "nonebot-plugin-userinfo>=0.2.4", ] requires-python = ">=3.8"