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);
|
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 GetDefaultUserAvatarUrl(ushort discriminator)
|
||||||
|
{
|
||||||
|
return $"{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)
|
||||||
@@ -37,11 +41,16 @@ namespace Discord
|
|||||||
format = imageId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png;
|
format = imageId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png;
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case ImageFormat.Gif: return "gif";
|
case ImageFormat.Gif:
|
||||||
case ImageFormat.Jpeg: return "jpeg";
|
return "gif";
|
||||||
case ImageFormat.Png: return "png";
|
case ImageFormat.Jpeg:
|
||||||
case ImageFormat.WebP: return "webp";
|
return "jpeg";
|
||||||
default: throw new ArgumentException(nameof(format));
|
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; }
|
string AvatarId { get; }
|
||||||
/// <summary> Gets the url to this user's avatar. </summary>
|
/// <summary> Gets the url to this user's avatar. </summary>
|
||||||
string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
|
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>
|
/// <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 GetDefaultAvatarUrl()
|
||||||
|
=> CDN.GetDefaultUserAvatarUrl(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;
|
||||||
@@ -37,23 +37,23 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
var newVal = ushort.Parse(model.Discriminator.Value);
|
var newVal = ushort.Parse(model.Discriminator.Value);
|
||||||
if (newVal != DiscriminatorValue)
|
if (newVal != DiscriminatorValue)
|
||||||
{
|
{
|
||||||
DiscriminatorValue = ushort.Parse(model.Discriminator.Value);
|
DiscriminatorValue = ushort.Parse(model.Discriminator.Value);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (model.Bot.IsSpecified && model.Bot.Value != IsBot)
|
if (model.Bot.IsSpecified && model.Bot.Value != IsBot)
|
||||||
{
|
{
|
||||||
IsBot = model.Bot.Value;
|
IsBot = model.Bot.Value;
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
if (model.Username.IsSpecified && model.Username.Value != Username)
|
if (model.Username.IsSpecified && model.Username.Value != Username)
|
||||||
{
|
{
|
||||||
Username = model.Username.Value;
|
Username = model.Username.Value;
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
return hasChanges;
|
return hasChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
|
public async Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
|
||||||
=> GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options) as IDMChannel;
|
=> 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)
|
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||||
|
|
||||||
|
public string GetDefaultAvatarUrl()
|
||||||
|
=> CDN.GetDefaultUserAvatarUrl(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;
|
||||||
|
|||||||
Reference in New Issue
Block a user