protected virtual void ActuallyHandleChannelOrQueryAka([NotNull] CommandMatch cmd, [NotNull] IUserMessageEventArgs e, [NotNull] Action <string> respond) { string nickToSearch = (string)cmd.Arguments[0]; if (!NickToMostRecentHost.ContainsKey(nickToSearch)) { respond($"I don\u2019t remember {nickToSearch}."); return; } var identifier = NickToMostRecentHost[nickToSearch]; var identifierParts = identifier.Parts; ImmutableList <HashSet <string> > matches; int matchDepth = HostToNicks.GetBestMatches(identifierParts, out matches); if (matchDepth == -1) { respond($"I don\u2019t remember any other nickname from {identifier} than {nickToSearch}."); return; } ImmutableList <HashSet <string> > fuzzyMatches = null; int fuzzyMatchDepth = -1; if (matchDepth == identifierParts.Count) { // do a fuzzy match too // replace the last item in identifierParts with the empty string var fuzzyIdentifierParts = identifierParts.SetItem(identifierParts.Count - 1, ""); fuzzyMatchDepth = HostToNicks.GetBestMatches(fuzzyIdentifierParts, out fuzzyMatches); } var otherNicks = new SortedSet <string>(matches.SelectMany(x => x)); var fuzzyOtherNicks = (fuzzyMatches == null) ? null : new SortedSet <string>(fuzzyMatches.SelectMany(x => x)); fuzzyOtherNicks?.ExceptWith(otherNicks); if (matchDepth == identifierParts.Count) { if (fuzzyOtherNicks != null && fuzzyOtherNicks.Count > 0) { respond($"{identifier}: {otherNicks.StringJoin(", ")}; fuzzy match ({fuzzyMatchDepth}/{identifierParts.Count}) also: {fuzzyOtherNicks.StringJoin(", ")}"); } else { respond($"{identifier}: {otherNicks.StringJoin(", ")}"); } } else { respond($"{identifier} fuzzy match ({matchDepth}/{identifierParts.Count}): {otherNicks.StringJoin(", ")}"); } }
protected virtual void RegisterNickname([NotNull] string host, [NotNull] string nick) { var identifier = GetUserIdentifier(host); var identifierParts = identifier.Parts; if (HostToNicks.ContainsKey(identifierParts)) { HostToNicks[identifierParts].Add(nick); } else { HostToNicks[identifierParts] = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { nick }; } NickToMostRecentHost[nick] = identifier; }