mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
✨ Feature: 添加多消息段命令解析支持 (#2419)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
This commit is contained in:
parent
6559b2ff27
commit
97a57c2f6e
@ -117,6 +117,11 @@ class TrieRule:
|
|||||||
# check whitespace
|
# check whitespace
|
||||||
arg_str = segment_text[len(pf.key) :]
|
arg_str = segment_text[len(pf.key) :]
|
||||||
arg_str_stripped = arg_str.lstrip()
|
arg_str_stripped = arg_str.lstrip()
|
||||||
|
# check next segment until arg detected or no text remain
|
||||||
|
while not arg_str_stripped and msg and msg[0].is_text():
|
||||||
|
arg_str += str(msg.pop(0))
|
||||||
|
arg_str_stripped = arg_str.lstrip()
|
||||||
|
|
||||||
has_arg = arg_str_stripped or msg
|
has_arg = arg_str_stripped or msg
|
||||||
if (
|
if (
|
||||||
has_arg
|
has_arg
|
||||||
|
@ -113,6 +113,36 @@ async def test_trie(app: App):
|
|||||||
command_whitespace=" ",
|
command_whitespace=" ",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
message = FakeMessageSegment.text("/fake-prefix ") + FakeMessageSegment.text(
|
||||||
|
" some args"
|
||||||
|
)
|
||||||
|
event = make_fake_event(_message=message)()
|
||||||
|
state = {}
|
||||||
|
TrieRule.get_value(bot, event, state)
|
||||||
|
assert state[PREFIX_KEY] == CMD_RESULT(
|
||||||
|
command=("fake-prefix",),
|
||||||
|
raw_command="/fake-prefix",
|
||||||
|
command_arg=FakeMessage("some args"),
|
||||||
|
command_start="/",
|
||||||
|
command_whitespace=" ",
|
||||||
|
)
|
||||||
|
|
||||||
|
message = (
|
||||||
|
FakeMessageSegment.text("/fake-prefix ")
|
||||||
|
+ FakeMessageSegment.text(" ")
|
||||||
|
+ FakeMessageSegment.text(" some args")
|
||||||
|
)
|
||||||
|
event = make_fake_event(_message=message)()
|
||||||
|
state = {}
|
||||||
|
TrieRule.get_value(bot, event, state)
|
||||||
|
assert state[PREFIX_KEY] == CMD_RESULT(
|
||||||
|
command=("fake-prefix",),
|
||||||
|
raw_command="/fake-prefix",
|
||||||
|
command_arg=FakeMessage("some args"),
|
||||||
|
command_start="/",
|
||||||
|
command_whitespace=" ",
|
||||||
|
)
|
||||||
|
|
||||||
del TrieRule.prefix["/fake-prefix"]
|
del TrieRule.prefix["/fake-prefix"]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user