Merge pull request #573 from james7132/auto-avatar
Automatic animated avatar detection
This commit is contained in:
@@ -5,7 +5,13 @@
|
||||
public static string GetApplicationIconUrl(ulong appId, string iconId)
|
||||
=> iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null;
|
||||
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, AvatarFormat format)
|
||||
=> avatarId != null ? $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{format.ToString().ToLower()}?size={size}" : null;
|
||||
{
|
||||
if (avatarId == null)
|
||||
return null;
|
||||
if (format == AvatarFormat.Auto)
|
||||
format = avatarId.StartsWith("a_") ? AvatarFormat.Gif : AvatarFormat.Png;
|
||||
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{format.ToString().ToLower()}?size={size}";
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
public enum AvatarFormat
|
||||
{
|
||||
Auto,
|
||||
WebP,
|
||||
Png,
|
||||
Jpeg,
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Discord
|
||||
/// <summary> Gets the id of this user's avatar. </summary>
|
||||
string AvatarId { get; }
|
||||
/// <summary> Gets the url to this user's avatar. </summary>
|
||||
string GetAvatarUrl(AvatarFormat format = AvatarFormat.Png, ushort size = 128);
|
||||
string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128);
|
||||
/// <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>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Discord.Rest
|
||||
public ushort DiscriminatorValue { get; private set; }
|
||||
public string AvatarId { get; private set; }
|
||||
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Png, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
@@ -41,7 +41,7 @@ namespace Discord.Rest
|
||||
if (model.Username.IsSpecified)
|
||||
Username = model.Username.Value;
|
||||
}
|
||||
|
||||
|
||||
public virtual async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetUserAsync(Id, options).ConfigureAwait(false);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Discord.Rpc
|
||||
public ushort DiscriminatorValue { get; private set; }
|
||||
public string AvatarId { get; private set; }
|
||||
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Png, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Discord.WebSocket
|
||||
internal abstract SocketGlobalUser GlobalUser { get; }
|
||||
internal abstract SocketPresence Presence { get; set; }
|
||||
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Png, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
|
||||
Reference in New Issue
Block a user