diff --git a/nonebot/rule.py b/nonebot/rule.py index da02b3d5..50465d37 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -117,6 +117,11 @@ class TrieRule: # check whitespace arg_str = segment_text[len(pf.key) :] 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 if ( has_arg diff --git a/tests/test_rule.py b/tests/test_rule.py index c3e5be5d..4bf1a22f 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -113,6 +113,36 @@ async def test_trie(app: App): 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"]