Skip to content

Commit 699d76b

Browse files
committed
⬆️ upgrade alconna to 1.8.40
modify aliases impl
1 parent 7aa37f3 commit 699d76b

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

pdm.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = [
77
dependencies = [
88
"tarina<0.7,>=0.6.8",
99
"nepattern<1.0,>=0.7.7",
10-
"arclet-alconna<2.0,>=1.8.35",
10+
"arclet-alconna<2.0,>=1.8.40",
1111
"arclet-alconna-tools>=0.7.10",
1212
"importlib-metadata>=4.13.0",
1313
"nonebot2>=2.3.0",

src/nonebot_plugin_alconna/matcher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def shortcut(
144144
arguments: list[Any] | None = None,
145145
fuzzy: bool = True,
146146
prefix: bool = False,
147+
compact: bool | None = True,
147148
wrapper: ShortcutRegWrapper | None = None,
148149
humanized: str | None = None,
149150
) -> type[Self]:
@@ -155,6 +156,7 @@ def shortcut(
155156
arguments (list[Any] | None, optional): 快捷命令参数, 默认为 `None`
156157
fuzzy (bool, optional): 是否允许命令后随参数, 默认为 `True`
157158
prefix (bool, optional): 是否调用时保留指令前缀, 默认为 `False`
159+
compact (bool, optional): 是否允许快捷指令与后随参数之间不包含分隔符,默认为 `True`. 当 compact 为 `None` 时表示跟随 CommandMeta.compact
158160
wrapper (ShortcutRegWrapper, optional): 快捷指令的正则匹配结果的额外处理函数, 默认为 `None`
159161
humanized (str, optional): 快捷指令的人类可读描述, 默认为 `None`
160162
@@ -176,6 +178,7 @@ def shortcut(cls, key: str | TPattern, args: ShortcutArgs | None = None, **kwarg
176178
arguments (list[Any] | None, optional): 快捷命令参数, 默认为 `None`
177179
fuzzy (bool, optional): 是否允许命令后随参数, 默认为 `True`
178180
prefix (bool, optional): 是否调用时保留指令前缀, 默认为 `False`
181+
compact (bool, optional): 是否允许快捷指令与后随参数之间不包含分隔符,默认为 `True`. 当 compact 为 `None` 时表示跟随 CommandMeta.compact
179182
wrapper (ShortcutRegWrapper, optional): 快捷指令的正则匹配结果的额外处理函数, 默认为 `None`
180183
humanized (str, optional): 快捷指令的人类可读描述, 默认为 `None`
181184

src/nonebot_plugin_alconna/rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _update(cmd_id: int):
144144
self.command = weakref.ref(command, lambda _: _update(_.__hash__()))
145145
if _aliases:
146146
for alias in _aliases:
147-
command.shortcut(alias, prefix=True)
147+
command.shortcut(alias, prefix=True, compact=False)
148148
self.skip = skip_for_unmatch
149149
self.executor = ExtensionExecutor(self, extensions, exclude_ext)
150150
self.executor.post_init(command)

tests/test_aliases.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
from nonebug import App
3+
from nonebot import get_adapter
4+
from nonebot.adapters.onebot.v11 import Bot, Adapter, Message
5+
6+
from tests.fake import fake_group_message_event_v11
7+
8+
9+
@pytest.mark.asyncio()
10+
async def test_command(app: App):
11+
from nonebot_plugin_alconna import Args, Alconna, on_alconna
12+
13+
alc = Alconna("weather", Args["city#城市名称", str])
14+
matcher = on_alconna(alc, aliases={"天气"})
15+
16+
@matcher.handle()
17+
async def _(city: str):
18+
await matcher.send(city)
19+
20+
async with app.test_matcher(matcher) as ctx: # type: ignore
21+
adapter = get_adapter(Adapter)
22+
bot = ctx.create_bot(base=Bot, adapter=adapter)
23+
event = fake_group_message_event_v11(message=Message("weather abcd"), user_id=123)
24+
ctx.receive_event(bot, event)
25+
ctx.should_call_send(event, "abcd")
26+
event1 = fake_group_message_event_v11(message=Message("天气 abcd"), user_id=123)
27+
ctx.receive_event(bot, event1)
28+
ctx.should_call_send(event1, "abcd")
29+
event2 = fake_group_message_event_v11(message=Message("天气abcd"), user_id=123)
30+
ctx.receive_event(bot, event2)
31+
ctx.should_not_pass_rule()

0 commit comments

Comments
 (0)