mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
✨ Feature: CommandGroup 支持命令别名添加前缀选项 (#2134)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -220,7 +220,7 @@ matcher_on_type = on_type(
|
||||
|
||||
|
||||
cmd_group = CommandGroup(
|
||||
"test",
|
||||
"prefix",
|
||||
rule=rule,
|
||||
permission=permission,
|
||||
handlers=[handler],
|
||||
@ -230,8 +230,30 @@ cmd_group = CommandGroup(
|
||||
block=True,
|
||||
state=state,
|
||||
)
|
||||
matcher_sub_cmd = cmd_group.command("sub")
|
||||
matcher_sub_shell_cmd = cmd_group.shell_command("sub")
|
||||
matcher_prefix_cmd = cmd_group.command("sub", aliases={"help", ("help", "foo")})
|
||||
matcher_prefix_shell_cmd = cmd_group.shell_command(
|
||||
"sub", aliases={"help", ("help", "foo")}
|
||||
)
|
||||
|
||||
|
||||
cmd_group_prefix_aliases = CommandGroup(
|
||||
"prefix",
|
||||
prefix_aliases=True,
|
||||
rule=rule,
|
||||
permission=permission,
|
||||
handlers=[handler],
|
||||
temp=True,
|
||||
expire_time=expire_time,
|
||||
priority=priority,
|
||||
block=True,
|
||||
state=state,
|
||||
)
|
||||
matcher_prefix_aliases_cmd = cmd_group_prefix_aliases.command(
|
||||
"sub", aliases={"help", ("help", "foo")}
|
||||
)
|
||||
matcher_prefix_aliases_shell_cmd = cmd_group_prefix_aliases.shell_command(
|
||||
"sub", aliases={"help", ("help", "foo")}
|
||||
)
|
||||
|
||||
|
||||
matcher_group = MatcherGroup(
|
||||
|
@ -41,10 +41,30 @@ from nonebot.rule import (
|
||||
),
|
||||
pytest.param("matcher_on_regex", lambda e: RegexRule("test"), True),
|
||||
pytest.param("matcher_on_type", lambda e: IsTypeRule(e), True),
|
||||
pytest.param("matcher_sub_cmd", lambda e: CommandRule([("test", "sub")]), True),
|
||||
pytest.param(
|
||||
"matcher_sub_shell_cmd",
|
||||
lambda e: ShellCommandRule([("test", "sub")], None),
|
||||
"matcher_prefix_cmd",
|
||||
lambda e: CommandRule([("prefix", "sub"), ("help",), ("help", "foo")]),
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"matcher_prefix_shell_cmd",
|
||||
lambda e: ShellCommandRule(
|
||||
[("prefix", "sub"), ("help",), ("help", "foo")], None
|
||||
),
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"matcher_prefix_aliases_cmd",
|
||||
lambda e: CommandRule(
|
||||
[("prefix", "sub"), ("prefix", "help"), ("prefix", "help", "foo")]
|
||||
),
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"matcher_prefix_aliases_shell_cmd",
|
||||
lambda e: ShellCommandRule(
|
||||
[("prefix", "sub"), ("prefix", "help"), ("prefix", "help", "foo")], None
|
||||
),
|
||||
True,
|
||||
),
|
||||
pytest.param("matcher_group_on", None, True),
|
||||
|
Reference in New Issue
Block a user