@@ -187,5 +187,10 @@ namespace Discord | |||||
/// <b>This will still require a stable clock on your system.</b> | /// <b>This will still require a stable clock on your system.</b> | ||||
/// </remarks> | /// </remarks> | ||||
public bool UseInteractionSnowflakeDate { get; set; } = true; | public bool UseInteractionSnowflakeDate { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets or sets if any user's <see cref="object.ToString"/> override formats the string in respect to bidirectional unicode. | |||||
/// </summary> | |||||
public bool FormatUsersInBidirectionalUnicode { get; set; } = true; | |||||
} | } | ||||
} | } |
@@ -107,13 +107,16 @@ namespace Discord | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Formats a user's username + discriminator while maintaining bidirectional unicode | |||||
/// Formats a user's username + discriminator. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="doBidirectional">To format the string in bidirectional unicode or not</param> | |||||
/// <param name="user">The user whos username and discriminator to format</param> | /// <param name="user">The user whos username and discriminator to format</param> | ||||
/// <returns>The username + discriminator</returns> | /// <returns>The username + discriminator</returns> | ||||
public static string UsernameAndDiscriminator(IUser user) | |||||
public static string UsernameAndDiscriminator(IUser user, bool doBidirectional) | |||||
{ | { | ||||
return $"\u2066{user.Username}\u2069#{user.Discriminator}"; | |||||
return doBidirectional | |||||
? $"\u2066{user.Username}\u2069#{user.Discriminator}" | |||||
: $"{user.Username}#{user.Discriminator}"; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -36,6 +36,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public TokenType TokenType => ApiClient.AuthTokenType; | public TokenType TokenType => ApiClient.AuthTokenType; | ||||
internal bool UseInteractionSnowflakeDate { get; private set; } | internal bool UseInteractionSnowflakeDate { get; private set; } | ||||
internal bool FormatUsersInBidirectionalUnicode { get; private set; } | |||||
/// <summary> Creates a new REST-only Discord client. </summary> | /// <summary> Creates a new REST-only Discord client. </summary> | ||||
internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client) | internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client) | ||||
@@ -49,6 +50,7 @@ namespace Discord.Rest | |||||
_isFirstLogin = config.DisplayInitialLog; | _isFirstLogin = config.DisplayInitialLog; | ||||
UseInteractionSnowflakeDate = config.UseInteractionSnowflakeDate; | UseInteractionSnowflakeDate = config.UseInteractionSnowflakeDate; | ||||
FormatUsersInBidirectionalUnicode = config.FormatUsersInBidirectionalUnicode; | |||||
ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => | ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => | ||||
{ | { | ||||
@@ -16,6 +16,8 @@ namespace Discord.Rest | |||||
public class RestUser : RestEntity<ulong>, IUser, IUpdateable | public class RestUser : RestEntity<ulong>, IUser, IUpdateable | ||||
{ | { | ||||
#region RestUser | #region RestUser | ||||
private readonly bool _useBidirectionalUnicode; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public bool IsBot { get; private set; } | public bool IsBot { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -51,6 +53,7 @@ namespace Discord.Rest | |||||
internal RestUser(BaseDiscordClient discord, ulong id) | internal RestUser(BaseDiscordClient discord, ulong id) | ||||
: base(discord, id) | : base(discord, id) | ||||
{ | { | ||||
_useBidirectionalUnicode = discord.FormatUsersInBidirectionalUnicode; | |||||
} | } | ||||
internal static RestUser Create(BaseDiscordClient discord, Model model) | internal static RestUser Create(BaseDiscordClient discord, Model model) | ||||
=> Create(discord, null, model, null); | => Create(discord, null, model, null); | ||||
@@ -129,8 +132,10 @@ namespace Discord.Rest | |||||
/// <returns> | /// <returns> | ||||
/// A string that resolves to Username#Discriminator of the user. | /// A string that resolves to Username#Discriminator of the user. | ||||
/// </returns> | /// </returns> | ||||
public override string ToString() => Format.UsernameAndDiscriminator(this); | |||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})"; | |||||
public override string ToString() | |||||
=> Format.UsernameAndDiscriminator(this, _useBidirectionalUnicode); | |||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this, _useBidirectionalUnicode)} ({Id}{(IsBot ? ", Bot" : "")})"; | |||||
#endregion | #endregion | ||||
#region IUser | #region IUser | ||||
@@ -17,6 +17,7 @@ namespace Discord.WebSocket | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public abstract class SocketUser : SocketEntity<ulong>, IUser | public abstract class SocketUser : SocketEntity<ulong>, IUser | ||||
{ | { | ||||
private readonly bool _useBidirectionalUnicode; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public abstract bool IsBot { get; internal set; } | public abstract bool IsBot { get; internal set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -56,6 +57,7 @@ namespace Discord.WebSocket | |||||
internal SocketUser(DiscordSocketClient discord, ulong id) | internal SocketUser(DiscordSocketClient discord, ulong id) | ||||
: base(discord, id) | : base(discord, id) | ||||
{ | { | ||||
_useBidirectionalUnicode = discord.FormatUsersInBidirectionalUnicode; | |||||
} | } | ||||
internal virtual bool Update(ClientState state, Model model) | internal virtual bool Update(ClientState state, Model model) | ||||
{ | { | ||||
@@ -117,8 +119,8 @@ namespace Discord.WebSocket | |||||
/// <returns> | /// <returns> | ||||
/// The full name of the user. | /// The full name of the user. | ||||
/// </returns> | /// </returns> | ||||
public override string ToString() => Format.UsernameAndDiscriminator(this); | |||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})"; | |||||
public override string ToString() => Format.UsernameAndDiscriminator(this, _useBidirectionalUnicode); | |||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this, _useBidirectionalUnicode)} ({Id}{(IsBot ? ", Bot" : "")})"; | |||||
internal SocketUser Clone() => MemberwiseClone() as SocketUser; | internal SocketUser Clone() => MemberwiseClone() as SocketUser; | ||||
} | } | ||||
} | } |