|
|
@@ -1,16 +1,17 @@ |
|
|
|
namespace Discord |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace Discord |
|
|
|
{ |
|
|
|
public static class CDN |
|
|
|
{ |
|
|
|
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) |
|
|
|
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, ImageFormat format) |
|
|
|
{ |
|
|
|
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}"; |
|
|
|
string extension = FormatToExtension(format, avatarId); |
|
|
|
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; |
|
|
|
} |
|
|
|
public static string GetGuildIconUrl(ulong guildId, string iconId) |
|
|
|
=> iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; |
|
|
@@ -20,5 +21,19 @@ |
|
|
|
=> iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null; |
|
|
|
public static string GetEmojiUrl(ulong emojiId) |
|
|
|
=> $"{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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |