Skip to content

Commit

Permalink
feat: 发送的指令参数错误后,回复对应指令的使用帮助 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed Dec 26, 2024
1 parent 254a1b1 commit c7cc255
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions nonebot_plugin_tsugu_bangdream_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
store_true,
command_manager,
referent,
on_alconna
on_alconna,
)

require("nonebot_plugin_userinfo")
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[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"},
]
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"
Expand Down

0 comments on commit c7cc255

Please sign in to comment.