def find_user(users: List[User], name_part: str) -> [User, None]: """Slow search, iterate over all users list, except if username == name_part But smarter cause it checks pertinence. """ name_part = unidecode(name_part.lower()) """ Ordre d'importance : * Est le display name * Pseudo démarre avec la recherche * % de match """ sort_rule = (("is_account_name", False), ("starts_with", True), ("match", True)) matches = [] for user in users: if user.bot: continue display_name = unidecode(user.display_name.lower()) username = unidecode(user.name.lower()) match = None names_comparaison = [] if name_part in display_name: names_comparaison.append( UserSearchResult(user, len(name_part) / len(display_name), display_name.startswith(name_part), False)) if name_part in username: names_comparaison.append( UserSearchResult(user, len(name_part) / len(username), username.startswith(name_part), True)) if names_comparaison: if len(names_comparaison) == 1: match = names_comparaison[0] else: match = Utils.multisort(names_comparaison, sort_rule)[0] if match: if match.match == 1: return match.user matches.append(match) if matches: Utils.multisort(matches, sort_rule) return matches[0].user return None
def _get_sorted_syntaxes(cls) -> List[CommandSyntax]: if cls._sorted_syntaxes is None: cls._sorted_syntaxes = cls.get_syntaxes().copy() Utils.multisort(cls._sorted_syntaxes, (("always_validate_input_format", False), ("param_count", True))) return cls._sorted_syntaxes