added UserDefaultAvatar to IUser (#973)
* added UserDefaultAvatar to IUser * pass ushort as discriminator * removed unneeded ushort.parse
This commit is contained in:
@@ -13,6 +13,10 @@ namespace Discord
|
||||
string extension = FormatToExtension(format, avatarId);
|
||||
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}";
|
||||
}
|
||||
public static string GetDefaultUserAvatarUrl(ushort discriminator)
|
||||
{
|
||||
return $"{DiscordConfig.CDNUrl}embed/avatars/{discriminator % 5}.png";
|
||||
}
|
||||
public static string GetGuildIconUrl(ulong guildId, string iconId)
|
||||
=> iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null;
|
||||
public static string GetGuildSplashUrl(ulong guildId, string splashId)
|
||||
@@ -37,11 +41,16 @@ namespace Discord
|
||||
format = imageId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png;
|
||||
switch (format)
|
||||
{
|
||||
case ImageFormat.Gif: return "gif";
|
||||
case ImageFormat.Jpeg: return "jpeg";
|
||||
case ImageFormat.Png: return "png";
|
||||
case ImageFormat.WebP: return "webp";
|
||||
default: throw new ArgumentException(nameof(format));
|
||||
case ImageFormat.Gif:
|
||||
return "gif";
|
||||
case ImageFormat.Jpeg:
|
||||
return "jpeg";
|
||||
case ImageFormat.Png:
|
||||
return "png";
|
||||
case ImageFormat.WebP:
|
||||
return "webp";
|
||||
default:
|
||||
throw new ArgumentException(nameof(format));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Discord
|
||||
string AvatarId { get; }
|
||||
/// <summary> Gets the url to this user's avatar. </summary>
|
||||
string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
|
||||
/// <summary> Gets the url to this user's default avatar. </summary>
|
||||
string GetDefaultAvatarUrl();
|
||||
/// <summary> Gets the per-username unique id for this user. </summary>
|
||||
string Discriminator { get; }
|
||||
/// <summary> Gets the per-username unique id for this user. </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.User;
|
||||
@@ -60,6 +60,9 @@ namespace Discord.Rest
|
||||
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
|
||||
public string GetDefaultAvatarUrl()
|
||||
=> CDN.GetDefaultUserAvatarUrl(DiscriminatorValue);
|
||||
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Discord.Rest;
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.User;
|
||||
@@ -37,23 +37,23 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var newVal = ushort.Parse(model.Discriminator.Value);
|
||||
if (newVal != DiscriminatorValue)
|
||||
{
|
||||
{
|
||||
DiscriminatorValue = ushort.Parse(model.Discriminator.Value);
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
if (model.Bot.IsSpecified && model.Bot.Value != IsBot)
|
||||
{
|
||||
{
|
||||
IsBot = model.Bot.Value;
|
||||
hasChanges = true;
|
||||
}
|
||||
if (model.Username.IsSpecified && model.Username.Value != Username)
|
||||
{
|
||||
{
|
||||
Username = model.Username.Value;
|
||||
hasChanges = true;
|
||||
}
|
||||
return hasChanges;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
|
||||
=> GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options) as IDMChannel;
|
||||
@@ -61,6 +61,9 @@ namespace Discord.WebSocket
|
||||
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
|
||||
public string GetDefaultAvatarUrl()
|
||||
=> CDN.GetDefaultUserAvatarUrl(DiscriminatorValue);
|
||||
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
internal SocketUser Clone() => MemberwiseClone() as SocketUser;
|
||||
|
||||
Reference in New Issue
Block a user