group search multimatches by displayed name
This commit is contained in:
parent
aeb0cf6854
commit
675236bb96
1 changed files with 28 additions and 21 deletions
|
|
@ -2397,7 +2397,18 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs):
|
|||
query=query
|
||||
)
|
||||
|
||||
for num, result in enumerate(matches):
|
||||
# group results by display name to properly disambiguate
|
||||
grouped_matches = defaultdict(list)
|
||||
for item in matches:
|
||||
group_key = (
|
||||
item.get_display_name(caller)
|
||||
if hasattr(item, "get_display_name")
|
||||
else query
|
||||
)
|
||||
grouped_matches[group_key].append(item)
|
||||
|
||||
for key, match_list in grouped_matches.items():
|
||||
for num, result in enumerate(match_list):
|
||||
# we need to consider that result could be a Command, where .aliases
|
||||
# is a list of strings
|
||||
if hasattr(result.aliases, "all"):
|
||||
|
|
@ -2411,11 +2422,7 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs):
|
|||
|
||||
error += _MULTIMATCH_TEMPLATE.format(
|
||||
number=num + 1,
|
||||
name=(
|
||||
result.get_display_name(caller)
|
||||
if hasattr(result, "get_display_name")
|
||||
else query
|
||||
),
|
||||
name=key,
|
||||
aliases=" [{alias}]".format(alias=";".join(aliases)) if aliases else "",
|
||||
info=result.get_extra_info(caller),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue