|
|
@@ -12,26 +12,45 @@ namespace Discord |
|
|
|
/// </summary> |
|
|
|
/// <param name="appId">The application identifier.</param> |
|
|
|
/// <param name="iconId">The icon identifier.</param> |
|
|
|
/// <param name="format">The format to return. Mustn't be a gif.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</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, ImageFormat format, ushort size) |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(iconId)) |
|
|
|
return null; |
|
|
|
if (format == ImageFormat.Gif) |
|
|
|
throw new ArgumentException("Requested image format mustn't be a gif."); |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
string extension = FormatToExtension(format, iconId); |
|
|
|
return $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.{extension}?size={size}"; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Returns a user avatar URL. |
|
|
|
/// </summary> |
|
|
|
/// <param name="userId">The user snowflake identifier.</param> |
|
|
|
/// <param name="avatarId">The avatar identifier.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <param name="format">The format to return.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <returns> |
|
|
|
/// A URL pointing to the user's avatar in the specified size. |
|
|
|
/// </returns> |
|
|
|
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, ImageFormat format) |
|
|
|
public static string GetUserAvatarUrl(ulong userId, string avatarId, ImageFormat format, ushort size) |
|
|
|
{ |
|
|
|
if (avatarId == null) |
|
|
|
if (string.IsNullOrWhiteSpace(avatarId)) |
|
|
|
return null; |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
string extension = FormatToExtension(format, avatarId); |
|
|
|
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; |
|
|
|
} |
|
|
@@ -51,8 +70,8 @@ namespace Discord |
|
|
|
/// </summary> |
|
|
|
/// <param name="guildId">The guild snowflake identifier.</param> |
|
|
|
/// <param name="iconId">The icon identifier.</param> |
|
|
|
/// <param name="format">The format to return. Mustn't be a gif.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <param name="format">The format to return.</param> |
|
|
|
/// <returns> |
|
|
|
/// A URL pointing to the guild's icon in the specified size. |
|
|
|
/// </returns> |
|
|
@@ -62,6 +81,10 @@ namespace Discord |
|
|
|
return null; |
|
|
|
if (format == ImageFormat.Gif) |
|
|
|
throw new ArgumentException("Requested image format mustn't be a gif."); |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
string extension = FormatToExtension(format, iconId); |
|
|
|
return $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.{extension}?size={size}"; |
|
|
@@ -71,44 +94,63 @@ namespace Discord |
|
|
|
/// </summary> |
|
|
|
/// <param name="guildId">The guild snowflake identifier.</param> |
|
|
|
/// <param name="splashId">The splash icon identifier.</param> |
|
|
|
/// <param name="format">The format to return. Mustn't be a gif.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <returns> |
|
|
|
/// A URL pointing to the guild's icon. |
|
|
|
/// </returns> |
|
|
|
public static string GetGuildSplashUrl(ulong guildId, string splashId) |
|
|
|
=> splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null; |
|
|
|
/// <summary> |
|
|
|
/// Returns a channel icon URL. |
|
|
|
/// </summary> |
|
|
|
/// <param name="channelId">The channel snowflake identifier.</param> |
|
|
|
/// <param name="iconId">The icon identifier.</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 GetGuildSplashUrl(ulong guildId, string splashId, ImageFormat format, ushort size) |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(splashId)) |
|
|
|
return null; |
|
|
|
if (format == ImageFormat.Gif) |
|
|
|
throw new ArgumentException("Requested image format mustn't be a gif."); |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
string extension = FormatToExtension(format, splashId); |
|
|
|
return $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.{ extension}?size={size}"; |
|
|
|
} |
|
|
|
/// <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. This can be any power of two between 16 and 2048.</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) |
|
|
|
{ |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
return $"{DiscordConfig.CDNUrl}emojis/{emojiId}.{(animated ? "gif" : "png")}?size={size}"; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Returns a Rich Presence asset URL. |
|
|
|
/// </summary> |
|
|
|
/// <param name="appId">The application identifier.</param> |
|
|
|
/// <param name="assetId">The asset identifier.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <param name="format">The format to return.</param> |
|
|
|
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> |
|
|
|
/// <returns> |
|
|
|
/// A URL pointing to the asset image in the specified size. |
|
|
|
/// </returns> |
|
|
|
public static string GetRichAssetUrl(ulong appId, string assetId, ushort size, ImageFormat format) |
|
|
|
public static string GetRichAssetUrl(ulong appId, string assetId, ImageFormat format, ushort size) |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(assetId)) |
|
|
|
return null; |
|
|
|
if (!(size >= 16 && size <= 2048)) |
|
|
|
throw new ArgumentOutOfRangeException("Size must be a power of two in a range between 16 and 2048."); |
|
|
|
if ((size & (size - 1)) != 0) |
|
|
|
throw new ArgumentException("Size must be a power of two."); |
|
|
|
|
|
|
|
string extension = FormatToExtension(format, ""); |
|
|
|
return $"{DiscordConfig.CDNUrl}app-assets/{appId}/{assetId}.{extension}?size={size}"; |
|
|
|
} |
|
|
|