Renamed AvatarFormat -> ImageFormat. Cleaned up.
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
namespace Discord
|
using System;
|
||||||
|
|
||||||
|
namespace Discord
|
||||||
{
|
{
|
||||||
public static class CDN
|
public static class CDN
|
||||||
{
|
{
|
||||||
public static string GetApplicationIconUrl(ulong appId, string iconId)
|
public static string GetApplicationIconUrl(ulong appId, string iconId)
|
||||||
=> iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null;
|
=> iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null;
|
||||||
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, AvatarFormat format)
|
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, ImageFormat format)
|
||||||
{
|
{
|
||||||
if (avatarId == null)
|
if (avatarId == null)
|
||||||
return null;
|
return null;
|
||||||
if (format == AvatarFormat.Auto)
|
string extension = FormatToExtension(format, avatarId);
|
||||||
format = avatarId.StartsWith("a_") ? AvatarFormat.Gif : AvatarFormat.Png;
|
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}";
|
||||||
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{format.ToString().ToLower()}?size={size}";
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
@@ -20,5 +21,19 @@
|
|||||||
=> iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null;
|
=> iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null;
|
||||||
public static string GetEmojiUrl(ulong emojiId)
|
public static string GetEmojiUrl(ulong emojiId)
|
||||||
=> $"{DiscordConfig.CDNUrl}emojis/{emojiId}.png";
|
=> $"{DiscordConfig.CDNUrl}emojis/{emojiId}.png";
|
||||||
|
|
||||||
|
private static string FormatToExtension(ImageFormat format, string imageId)
|
||||||
|
{
|
||||||
|
if (format == ImageFormat.Auto)
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
public enum AvatarFormat
|
public enum ImageFormat
|
||||||
{
|
{
|
||||||
Auto,
|
Auto,
|
||||||
WebP,
|
WebP,
|
||||||
@@ -7,7 +7,7 @@ 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. </summary>
|
||||||
string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128);
|
string GetAvatarUrl(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>
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ namespace Discord.Rest
|
|||||||
public ushort DiscriminatorValue { get; private set; }
|
public ushort DiscriminatorValue { get; private set; }
|
||||||
public string AvatarId { get; private set; }
|
public string AvatarId { get; private set; }
|
||||||
|
|
||||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||||
|
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||||
public string Mention => MentionUtils.MentionUser(Id);
|
public string Mention => MentionUtils.MentionUser(Id);
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ namespace Discord.Rpc
|
|||||||
public ushort DiscriminatorValue { get; private set; }
|
public ushort DiscriminatorValue { get; private set; }
|
||||||
public string AvatarId { get; private set; }
|
public string AvatarId { get; private set; }
|
||||||
|
|
||||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||||
|
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||||
public string Mention => MentionUtils.MentionUser(Id);
|
public string Mention => MentionUtils.MentionUser(Id);
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ namespace Discord.WebSocket
|
|||||||
internal abstract SocketGlobalUser GlobalUser { get; }
|
internal abstract SocketGlobalUser GlobalUser { get; }
|
||||||
internal abstract SocketPresence Presence { get; set; }
|
internal abstract SocketPresence Presence { get; set; }
|
||||||
|
|
||||||
public string GetAvatarUrl(AvatarFormat format = AvatarFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||||
|
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||||
public string Mention => MentionUtils.MentionUser(Id);
|
public string Mention => MentionUtils.MentionUser(Id);
|
||||||
|
|||||||
Reference in New Issue
Block a user