@@ -12,23 +12,35 @@ namespace Discord
/// </summary>
/// <param name="teamId">The team identifier.</param>
/// <param name="iconId">The icon identifier.</param>
/// <param name="size">The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the team's icon.
/// </returns>
public static string GetTeamIconUrl(ulong teamId, string iconId)
=> iconId != null ? $"{DiscordConfig.CDNUrl}team-icons/{teamId}/{iconId}.jpg" : null;
public static string GetTeamIconUrl(ulong teamId, string iconId, ushort size, ImageFormat format)
{
if (iconId == null)
return null;
string extension = FormatToExtension(format, string.Empty);
return $"{DiscordConfig.CDNUrl}team-icons/{teamId}/{iconId}.{extension}?size={size}";
}
/// <summary>
/// Returns an application icon URL.
/// </summary>
/// <param name="appId">The application identifier.</param>
/// <param name="iconId">The icon identifier.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the application's icon.
/// </returns>
public static string GetApplicationIconUrl(ulong appId, string iconId)
=> iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null;
public static string GetApplicationIconUrl(ulong appId, string iconId, ushort size, ImageFormat format)
{
if (iconId == null)
return null;
string extension = FormatToExtension(format, string.Empty);
return $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.{extension}?size={size}";
}
/// <summary>
/// Returns a user avatar URL.
/// </summary>
@@ -62,67 +74,101 @@ namespace Discord
/// </summary>
/// <param name="guildId">The guild snowflake identifier.</param>
/// <param name="iconId">The icon identifier.</param>
/// <param name="size">The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the guild's icon.
/// </returns>
public static string GetGuildIconUrl(ulong guildId, string iconId)
=> iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null;
public static string GetGuildIconUrl(ulong guildId, string iconId, ushort size, ImageFormat format)
{
if (iconId == null)
return null;
string extension = FormatToExtension(format, iconId);
return $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.{extension}?size={size}";
}
/// <summary>
/// Returns a guild splash URL.
/// </summary>
/// <param name="guildId">The guild snowflake identifier.</param>
/// <param name="splashId">The splash icon identifier.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the guild's splash.
/// </returns>
public static string GetGuildSplashUrl(ulong guildId, string splashId)
=> splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null;
public static string GetGuildSplashUrl(ulong guildId, string splashId, ushort size, ImageFormat format)
{
if (splashId == null)
return null;
string extension = FormatToExtension(format, string.Empty);
return $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.{extension}?size={size}";
}
/// <summary>
/// Returns a guild discovery splash URL.
/// </summary>
/// <param name="guildId">The guild snowflake identifier.</param>
/// <param name="discoverySplashId">The discovery splash icon identifier.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the guild's discovery splash.
/// </returns>
public static string GetGuildDiscoverySplashUrl(ulong guildId, string discoverySplashId)
=> discoverySplashId != null ? $"{DiscordConfig.CDNUrl}discovery-splashes/{guildId}/{discoverySplashId}.jpg" : null;
public static string GetGuildDiscoverySplashUrl(ulong guildId, string discoverySplashId, ushort size, ImageFormat format)
{
if (discoverySplashId == null)
return null;
string extension = FormatToExtension(format, string.Empty);
return $"{DiscordConfig.CDNUrl}discovery-splashes/{guildId}/{discoverySplashId}.{extension}?size={size}";
}
/// <summary>
/// Returns a channel icon URL.
/// </summary>
/// <param name="channelId">The channel snowflake identifier.</param>
/// <param name="iconId">The icon identifier.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the channel's icon.
/// </returns>
public static string GetChannelIconUrl(ulong channelId, string iconId)
=> iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null;
public static string GetChannelIconUrl(ulong channelId, string iconId, ushort size, ImageFormat format)
{
if (iconId == null)
return null;
string extension = FormatToExtension(format, iconId);
return $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.{extension}?size={size}";
}
/// <summary>
/// Returns a guild banner URL.
/// </summary>
/// <param name="guildId">The guild snowflake identifier.</param>
/// <param name="bannerId">The banner image identifier.</param>
/// <param name="size">The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048 inclusive.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the guild's banner image.
/// </returns>
public static string GetGuildBannerUrl(ulong guildId, string bannerId, ushort? size = null)
public static string GetGuildBannerUrl(ulong guildId, string bannerId, ushort? size = null, ImageFormat? format = null )
{
if (!string.IsNullOrEmpty(bannerId))
return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.jpg" + (size.HasValue ? $"?size={size}" : string.Empty);
return null;
if (string.IsNullOrEmpty(bannerId))
return null;
string extension = format.HasValue ? FormatToExtension(format.Value, string.Empty) : "png";
return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.{extension}" + (size.HasValue ? $"?size={size}" : string.Empty);
}
/// <summary>
/// Returns an emoji URL.
/// </summary>
/// <param name="emojiId">The emoji snowflake identifier.</param>
/// <param name="animated">Whether this emoji is animated.</param>
/// <param name="size">The size of the image to return in horizontal pixels. This can be any power of two between 16 and 128.</param>
/// <param name="format">The format to return.</param>
/// <returns>
/// A URL pointing to the custom emote.
/// </returns>
public static string GetEmojiUrl(ulong emojiId, bool animated)
=> $"{DiscordConfig.CDNUrl}emojis/{emojiId}.{(animated ? "gif" : "png")}";
public static string GetEmojiUrl(ulong emojiId, bool animated, ushort size, ImageFormat format)
{
string extension = format == ImageFormat.Auto && animated ? "gif" : FormatToExtension(format, string.Empty);
return $"{DiscordConfig.CDNUrl}emojis/{emojiId}.{extension}?size={size}";
}
/// <summary>
/// Returns a Rich Presence asset URL.
@@ -136,7 +182,7 @@ namespace Discord
/// </returns>
public static string GetRichAssetUrl(ulong appId, string assetId, ushort size, ImageFormat format)
{
string extension = FormatToExtension(format, "" );
string extension = FormatToExtension(format, string.Empty );
return $"{DiscordConfig.CDNUrl}app-assets/{appId}/{assetId}.{extension}?size={size}";
}
@@ -173,6 +219,8 @@ namespace Discord
return "png";
case ImageFormat.WebP:
return "webp";
case ImageFormat.Lottie:
return "json";
default:
throw new ArgumentException(nameof(format));
}