Fix command start bug

This commit is contained in:
Richard Chien 2018-07-03 17:32:12 +08:00
parent 1d0885ef2e
commit 4ab1f4a01b

View File

@ -28,7 +28,7 @@ _sessions = {}
class Command: class Command:
__slots__ = ( __slots__ = (
'name', 'func', 'permission', 'only_to_me', 'args_parser_func') 'name', 'func', 'permission', 'only_to_me', 'args_parser_func')
def __init__(self, *, name: Tuple[str], func: Callable, permission: int, def __init__(self, *, name: Tuple[str], func: Callable, permission: int,
only_to_me: bool): only_to_me: bool):
@ -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