using System; namespace Discord { /// /// Represents a class containing the strings related to various Content Delivery Networks (CDNs). /// public static class CDN { /// /// Returns an application icon URL. /// /// The application identifier. /// The icon identifier. /// /// A URL pointing to the application's icon. /// public static string GetApplicationIconUrl(ulong appId, string iconId) => iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null; /// /// Returns a user avatar URL. /// /// The user snowflake identifier. /// The avatar identifier. /// The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048. /// The format to return. /// /// A URL pointing to the user's avatar in the specified size. /// public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, ImageFormat format) { if (avatarId == null) return null; string extension = FormatToExtension(format, avatarId); return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; } /// /// Returns the default user avatar URL. /// /// The discriminator value of a user. /// /// A URL pointing to the user's default avatar when one isn't set. /// public static string GetDefaultUserAvatarUrl(ushort discriminator) { return $"{DiscordConfig.CDNUrl}embed/avatars/{discriminator % 5}.png"; } /// /// Returns an icon URL. /// /// The guild snowflake identifier. /// The icon identifier. /// /// A URL pointing to the guild's icon. /// public static string GetGuildIconUrl(ulong guildId, string iconId) => iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; /// /// Returns a guild splash URL. /// /// The guild snowflake identifier. /// The splash icon identifier. /// /// A URL pointing to the guild's icon. /// public static string GetGuildSplashUrl(ulong guildId, string splashId) => splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null; /// /// Returns a channel icon URL. /// /// The channel snowflake identifier. /// The icon identifier. /// /// A URL pointing to the channel's icon. /// public static string GetChannelIconUrl(ulong channelId, string iconId) => iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null; /// /// Returns a guild banner URL. /// /// The guild snowflake identifier. /// The banner image identifier. /// The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048 inclusive. /// /// A URL pointing to the guild's banner image. /// public static string GetGuildBannerUrl(ulong guildId, string bannerId, ushort? size = null) { if (!string.IsNullOrEmpty(bannerId)) return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.jpg" + (size.HasValue ? $"?size={size}" : string.Empty); return null; } /// /// Returns an emoji URL. /// /// The emoji snowflake identifier. /// Whether this emoji is animated. /// /// A URL pointing to the custom emote. /// public static string GetEmojiUrl(ulong emojiId, bool animated) => $"{DiscordConfig.CDNUrl}emojis/{emojiId}.{(animated ? "gif" : "png")}"; /// /// Returns a Rich Presence asset URL. /// /// The application identifier. /// The asset identifier. /// The size of the image to return in. This can be any power of two between 16 and 2048. /// The format to return. /// /// A URL pointing to the asset image in the specified size. /// public static string GetRichAssetUrl(ulong appId, string assetId, ushort size, ImageFormat format) { string extension = FormatToExtension(format, ""); return $"{DiscordConfig.CDNUrl}app-assets/{appId}/{assetId}.{extension}?size={size}"; } /// /// Returns a Spotify album URL. /// /// The identifier for the album art (e.g. 6be8f4c8614ecf4f1dd3ebba8d8692d8ce4951ac). /// /// A URL pointing to the Spotify album art. /// public static string GetSpotifyAlbumArtUrl(string albumArtId) => $"https://i.scdn.co/image/{albumArtId}"; /// /// Returns a Spotify direct URL for a track. /// /// The identifier for the track (e.g. 4uLU6hMCjMI75M1A2tKUQC). /// /// A URL pointing to the Spotify track. /// public static string GetSpotifyDirectUrl(string trackId) => $"https://open.spotify.com/track/{trackId}"; 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)); } } } }