mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 04:56:57 +08:00
Fix command start bug
This commit is contained in:
parent
1d0885ef2e
commit
4ab1f4a01b
@ -242,20 +242,26 @@ def _new_command_session(bot: CQHttp,
|
|||||||
"""
|
"""
|
||||||
msg = str(ctx['message']).lstrip()
|
msg = str(ctx['message']).lstrip()
|
||||||
|
|
||||||
|
matched_start = None
|
||||||
for start in bot.config.COMMAND_START:
|
for start in bot.config.COMMAND_START:
|
||||||
if isinstance(start, type(re.compile(''))):
|
if isinstance(start, type(re.compile(''))):
|
||||||
m = start.search(msg)
|
m = start.search(msg)
|
||||||
if m:
|
if m and m.start(0) == 0:
|
||||||
full_command = msg[len(m.group(0)):].lstrip()
|
if matched_start is None or \
|
||||||
break
|
len(m.group(0)) > len(matched_start):
|
||||||
|
matched_start = m.group(0)
|
||||||
elif isinstance(start, str):
|
elif isinstance(start, str):
|
||||||
if msg.startswith(start):
|
if msg.startswith(start):
|
||||||
full_command = msg[len(start):].lstrip()
|
if matched_start is None or \
|
||||||
break
|
len(start) > len(matched_start):
|
||||||
else:
|
matched_start = start
|
||||||
|
|
||||||
|
if matched_start is None:
|
||||||
# it's not a command
|
# it's not a command
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
full_command = msg[len(matched_start):].lstrip()
|
||||||
|
|
||||||
if not full_command:
|
if not full_command:
|
||||||
# command is empty
|
# command is empty
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user