src/DiscordBot/Core/Functions.cs
/// <summary>
/// Finds and returns a user with the most similar name to the string passed through.
/// Returns a null user if there are no matches.
/// </summary>
Finds and returns a user with the most similar name to the string passed through.
Returns a null user if there are no matches.
Finds and returns a user with the most similar name to the string passed through . Returns a null user if there are no matches .
public static SocketUser GetUserWithSimilarName(string testName)
        {
            if (testName.Trim().Equals(string.Empty)) return null;
            var accounts = UserAccounts.GetAccounts();
            testName = testName.ToLower();
            var result = from acc in accounts
                         where Global.GetSocketUserWithId(acc.Id).Username.ToLower().Contains(testName)
                         select Global.GetSocketUserWithId(acc.Id);
            List<string> resultUsernames = new List<string>();
            List<ulong> resultIds = new List<ulong>();
            foreach (SocketUser u in result)
            {
                resultUsernames.Add(u.Username);
                resultIds.Add(u.Id);
            }
            if (resultIds.Count == 0) return null;
            ulong idMatch = GetMatch(resultIds, resultUsernames, testName);
            SocketUser closestName = Global.GetSocketUserWithId(idMatch);
            return closestName;
        }
public static SocketUser GetUserWithSimilarName ( string testName ) { if ( testName . Trim ( ) . Equals ( string . Empty ) ) return null ; var accounts = UserAccounts . GetAccounts ( ) ; testName = testName . ToLower ( ) ; var result = from acc in accounts where Global . GetSocketUserWithId ( acc . Id ) . Username . ToLower ( ) . Contains ( testName ) select Global . GetSocketUserWithId ( acc . Id ) ; List < string > resultUsernames = new List < string > ( ) ; List < ulong > resultIds = new List < ulong > ( ) ; foreach ( SocketUser u in result ) { resultUsernames . Add ( u . Username ) ; resultIds . Add ( u . Id ) ; } if ( resultIds . Count == 0 ) return null ; ulong idMatch = GetMatch ( resultIds , resultUsernames , testName ) ; SocketUser closestName = Global . GetSocketUserWithId ( idMatch ) ; return closestName ; }
Finds and returns a user with the most similar name to the string passed through.
Finds and returns a user with the most similar name to the string passed through .
// Retrieves the SocketUsers with similar usernames to the passed name
testName
string