From 97a57c2f6e63c2f69fae821c282ffcaa3488426e Mon Sep 17 00:00:00 2001 From: RainEggplant Date: Wed, 18 Oct 2023 15:55:09 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Feature:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E6=B6=88=E6=81=AF=E6=AE=B5=E5=91=BD=E4=BB=A4=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=94=AF=E6=8C=81=20(#2419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> --- nonebot/rule.py | 5 +++++ tests/test_rule.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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"]