Skip to content

Commit

Permalink
feature: Handle bidirectional usernames (#1943)
Browse files Browse the repository at this point in the history
* Initial implementation

* Update summary
  • Loading branch information
quinchs authored Nov 25, 2021
1 parent 143ca6d commit 10afd96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Discord.Net.Core/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,15 @@ public static string StripMarkDown(string text)
var newText = Regex.Replace(text, @"(\*|_|`|~|>|\\)", "");
return newText;
}

/// <summary>
/// Formats a user's username + discriminator while maintaining bidirectional unicode
/// </summary>
/// <param name="user">The user whos username and discriminator to format</param>
/// <returns>The username + discriminator</returns>
public static string UsernameAndDiscriminator(IUser user)
{
return $"\u2066{user.Username}\u2069#{user.Discriminator}";
}
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Entities/Users/RestUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public string GetDefaultAvatarUrl()
/// <returns>
/// A string that resolves to Username#Discriminator of the user.
/// </returns>
public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
public override string ToString() => Format.UsernameAndDiscriminator(this);
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})";
#endregion

#region IUser
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public string GetDefaultAvatarUrl()
/// <returns>
/// The full name of the user.
/// </returns>
public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
public override string ToString() => Format.UsernameAndDiscriminator(this);
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})";
internal SocketUser Clone() => MemberwiseClone() as SocketUser;
}
}

0 comments on commit 10afd96

Please sign in to comment.