feature: Make bidirectional formatting optional (#2204)
* Init * Clearing up comment on config entry. * Update user entities to remove storage of the setting Co-authored-by: Quin Lynch <lynchquin@gmail.com>
This commit is contained in:
@@ -187,5 +187,15 @@ namespace Discord
|
||||
/// <b>This will still require a stable clock on your system.</b>
|
||||
/// </remarks>
|
||||
public bool UseInteractionSnowflakeDate { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the Rest/Socket user <see cref="object.ToString"/> override formats the string in respect to bidirectional unicode.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, the returned value will be "?Discord?#1234", to work with bidirectional usernames.
|
||||
/// <br/>
|
||||
/// If set to <see langword="false"/>, this value will be "Discord#1234".
|
||||
/// </remarks>
|
||||
public bool FormatUsersInBidirectionalUnicode { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +107,16 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a user's username + discriminator while maintaining bidirectional unicode
|
||||
/// Formats a user's username + discriminator.
|
||||
/// </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>
|
||||
/// <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 />
|
||||
public TokenType TokenType => ApiClient.AuthTokenType;
|
||||
internal bool UseInteractionSnowflakeDate { get; private set; }
|
||||
internal bool FormatUsersInBidirectionalUnicode { get; private set; }
|
||||
|
||||
/// <summary> Creates a new REST-only Discord client. </summary>
|
||||
internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client)
|
||||
@@ -49,6 +50,7 @@ namespace Discord.Rest
|
||||
_isFirstLogin = config.DisplayInitialLog;
|
||||
|
||||
UseInteractionSnowflakeDate = config.UseInteractionSnowflakeDate;
|
||||
FormatUsersInBidirectionalUnicode = config.FormatUsersInBidirectionalUnicode;
|
||||
|
||||
ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) =>
|
||||
{
|
||||
|
||||
@@ -129,8 +129,10 @@ namespace Discord.Rest
|
||||
/// <returns>
|
||||
/// A string that resolves to Username#Discriminator of the user.
|
||||
/// </returns>
|
||||
public override string ToString() => Format.UsernameAndDiscriminator(this);
|
||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
public override string ToString()
|
||||
=> Format.UsernameAndDiscriminator(this, Discord.FormatUsersInBidirectionalUnicode);
|
||||
|
||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this, Discord.FormatUsersInBidirectionalUnicode)} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
#endregion
|
||||
|
||||
#region IUser
|
||||
|
||||
@@ -117,8 +117,8 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// The full name of the user.
|
||||
/// </returns>
|
||||
public override string ToString() => Format.UsernameAndDiscriminator(this);
|
||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
public override string ToString() => Format.UsernameAndDiscriminator(this, Discord.FormatUsersInBidirectionalUnicode);
|
||||
private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this, Discord.FormatUsersInBidirectionalUnicode)} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
internal SocketUser Clone() => MemberwiseClone() as SocketUser;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user