| @@ -13,6 +13,8 @@ namespace Discord | |||||
| string extension = FormatToExtension(format, avatarId); | string extension = FormatToExtension(format, avatarId); | ||||
| return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; | return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; | ||||
| } | } | ||||
| public static string GetUserDefaultAvatarUrl(ushort discriminator) | |||||
| => $"{DiscordConfig.CDNUrl}embed/avatars/{discriminator % 5}.png"; | |||||
| public static string GetGuildIconUrl(ulong guildId, string iconId) | public static string GetGuildIconUrl(ulong guildId, string iconId) | ||||
| => iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; | => iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; | ||||
| public static string GetGuildSplashUrl(ulong guildId, string splashId) | public static string GetGuildSplashUrl(ulong guildId, string splashId) | ||||
| @@ -6,8 +6,13 @@ namespace Discord | |||||
| { | { | ||||
| /// <summary> Gets the id of this user's avatar. </summary> | /// <summary> Gets the id of this user's avatar. </summary> | ||||
| string AvatarId { get; } | string AvatarId { get; } | ||||
| /// <summary> Gets the url to this user's avatar. </summary> | |||||
| /// <summary> Gets the url to this user's avatar or null if it's the default one. </summary> | |||||
| string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128); | string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128); | ||||
| /// <summary> | |||||
| /// <para>Gets the url to this user's avatar or the default one if he doesn't have a custom one.</para> | |||||
| /// <para>The default avatar image is a 256x256 PNG.</para> | |||||
| /// </summary> | |||||
| string GetAvatarUrlOrDefault(ImageFormat format = ImageFormat.Auto, ushort size = 128); | |||||
| /// <summary> Gets the per-username unique id for this user. </summary> | /// <summary> Gets the per-username unique id for this user. </summary> | ||||
| string Discriminator { get; } | string Discriminator { get; } | ||||
| /// <summary> Gets the per-username unique id for this user. </summary> | /// <summary> Gets the per-username unique id for this user. </summary> | ||||
| @@ -1,4 +1,4 @@ | |||||
| using System; | |||||
| using System; | |||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
| @@ -60,6 +60,9 @@ namespace Discord.Rest | |||||
| public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | ||||
| public string GetAvatarUrlOrDefault(ImageFormat format = ImageFormat.Auto, ushort size = 128) | |||||
| => CDN.GetUserAvatarUrl(Id, AvatarId, size, format) ?? CDN.GetUserDefaultAvatarUrl(DiscriminatorValue); | |||||
| public override string ToString() => $"{Username}#{Discriminator}"; | public override string ToString() => $"{Username}#{Discriminator}"; | ||||
| private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | ||||
| @@ -1,4 +1,4 @@ | |||||
| using Discord.Rest; | |||||
| using Discord.Rest; | |||||
| using System; | using System; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
| @@ -61,6 +61,9 @@ namespace Discord.WebSocket | |||||
| public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | ||||
| public string GetAvatarUrlOrDefault(ImageFormat format = ImageFormat.Auto, ushort size = 128) | |||||
| => CDN.GetUserAvatarUrl(Id, AvatarId, size, format) ?? CDN.GetUserDefaultAvatarUrl(DiscriminatorValue); | |||||
| public override string ToString() => $"{Username}#{Discriminator}"; | public override string ToString() => $"{Username}#{Discriminator}"; | ||||
| private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | ||||
| internal SocketUser Clone() => MemberwiseClone() as SocketUser; | internal SocketUser Clone() => MemberwiseClone() as SocketUser; | ||||