Better handle multimatch index out of scope. Resolve #2207.

This commit is contained in:
Griatch 2020-11-13 20:39:44 +01:00
parent aac9eb17d9
commit 5f8911ec72
4 changed files with 15 additions and 9 deletions

View file

@ -209,10 +209,15 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
quality = [mat[4] for mat in matches]
matches = matches[-quality.count(quality[-1]) :]
if len(matches) > 1 and match_index is not None and 0 < match_index <= len(matches):
if len(matches) > 1 and match_index is not None:
# We couldn't separate match by quality, but we have an
# index argument to tell us which match to use.
matches = [matches[match_index - 1]]
if 0 < match_index <= len(matches):
matches = [matches[match_index - 1]]
else:
# we tried to give an index outside of the range - this means
# a no-match
matches = []
# no matter what we have at this point, we have to return it.
return matches