Browse Source

Allow the user to define guild icon's format and size

pull/1231/head
gab 6 years ago
parent
commit
d22f6955f9
4 changed files with 15 additions and 6 deletions
  1. +10
    -3
      src/Discord.Net.Core/CDN.cs
  2. +1
    -1
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  3. +2
    -1
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  4. +2
    -1
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 10
- 3
src/Discord.Net.Core/CDN.cs View File

@@ -51,11 +51,18 @@ 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. 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.
/// A URL pointing to the guild's icon in the specified size.
/// </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>


+ 1
- 1
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -72,7 +72,7 @@ namespace Discord
/// <returns>
/// A URL pointing to the guild's icon; <c>null</c> if none is set.
/// </returns>
string IconUrl { get; }
string GetIconUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
/// <summary>
/// Gets the ID of this guild's splash image.
/// </summary>


+ 2
- 1
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -59,7 +59,8 @@ namespace Discord.Rest
[Obsolete("DefaultChannelId is deprecated, use GetDefaultChannelAsync")]
public ulong DefaultChannelId => Id;
/// <inheritdoc />
public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);
public string GetIconUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildIconUrl(Id, IconId, size, format);
/// <inheritdoc />
public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);



+ 2
- 1
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -97,7 +97,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <inheritdoc />
public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);
public string GetIconUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildIconUrl(Id, IconId, size, format);
/// <inheritdoc />
public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);
/// <summary> Indicates whether the client has all the members downloaded to the local guild cache. </summary>


Loading…
Cancel
Save