[Feature] Support for the new username system (#2696)
* update a lot of stuff * update CDN for new avatar calculation * whoops, forgot to commit * handle `null` values * Remove duplicate line Co-authored-by: Dmitry <dimson-n@users.noreply.github.com> * updates * Apply suggestions from code review Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> * Apply suggestion Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> * update `SocketThreadUSer` --------- Co-authored-by: Dmitry <dimson-n@users.noreply.github.com> Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
This commit is contained in:
@@ -48,7 +48,10 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Global)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Guild)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Guild)";
|
||||
|
||||
internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,10 @@ namespace Discord.WebSocket
|
||||
return entity;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Group)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Group)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Group)";
|
||||
|
||||
internal new SocketGroupUser Clone() => MemberwiseClone() as SocketGroupUser;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@ namespace Discord.WebSocket
|
||||
/// Gets the guild the user is in.
|
||||
/// </summary>
|
||||
public SocketGuild Guild { get; }
|
||||
/// <inheritdoc />
|
||||
public string DisplayName => Nickname ?? Username;
|
||||
|
||||
/// <inheritdoc cref="IGuildUser.DisplayName"/>
|
||||
public string DisplayName => Nickname ?? GlobalName ?? Username;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Nickname { get; private set; }
|
||||
/// <inheritdoc/>
|
||||
@@ -265,7 +267,9 @@ namespace Discord.WebSocket
|
||||
public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetGuildUserAvatarUrl(Id, Guild.Id, GuildAvatarId, size, format);
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Guild)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Guild)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Guild)";
|
||||
|
||||
internal new SocketGuildUser Clone()
|
||||
{
|
||||
|
||||
@@ -91,7 +91,10 @@ namespace Discord.WebSocket
|
||||
public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
|
||||
=> UserHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Self)";
|
||||
|
||||
internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Discord.WebSocket
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string DisplayName
|
||||
=> GuildUser.Nickname ?? GuildUser.Username;
|
||||
=> GuildUser.Nickname ?? GuildUser.GlobalName ?? GuildUser.Username;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Nickname
|
||||
|
||||
@@ -42,7 +42,10 @@ namespace Discord.WebSocket
|
||||
return entity;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Unknown)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Unknown)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Unknown)";
|
||||
|
||||
internal new SocketUnknownUser Clone() => MemberwiseClone() as SocketUnknownUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ namespace Discord.WebSocket
|
||||
internal abstract SocketGlobalUser GlobalUser { get; set; }
|
||||
internal abstract SocketPresence Presence { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GlobalName { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
/// <inheritdoc />
|
||||
@@ -68,10 +71,10 @@ namespace Discord.WebSocket
|
||||
}
|
||||
if (model.Discriminator.IsSpecified)
|
||||
{
|
||||
var newVal = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
var newVal = ushort.Parse(model.Discriminator.GetValueOrDefault(null) ?? "0", NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
if (newVal != DiscriminatorValue)
|
||||
{
|
||||
DiscriminatorValue = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
DiscriminatorValue = ushort.Parse(model.Discriminator.GetValueOrDefault(null) ?? "0", NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +93,11 @@ namespace Discord.WebSocket
|
||||
PublicFlags = model.PublicFlags.Value;
|
||||
hasChanges = true;
|
||||
}
|
||||
if (model.GlobalName.IsSpecified)
|
||||
{
|
||||
GlobalName = model.GlobalName.Value;
|
||||
hasChanges = true;
|
||||
}
|
||||
return hasChanges;
|
||||
}
|
||||
|
||||
@@ -109,7 +117,9 @@ namespace Discord.WebSocket
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetDefaultAvatarUrl()
|
||||
=> CDN.GetDefaultUserAvatarUrl(DiscriminatorValue);
|
||||
=> DiscriminatorValue != 0
|
||||
? CDN.GetDefaultUserAvatarUrl(DiscriminatorValue)
|
||||
: CDN.GetDefaultUserAvatarUrl(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full name of the user (e.g. Example#0001).
|
||||
|
||||
@@ -49,7 +49,10 @@ namespace Discord.WebSocket
|
||||
return entity;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)";
|
||||
private string DebuggerDisplay => DiscriminatorValue != 0
|
||||
? $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)"
|
||||
: $"{Username} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)";
|
||||
|
||||
internal new SocketWebhookUser Clone() => MemberwiseClone() as SocketWebhookUser;
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user