From 42b693c8ebe8a5e8f4e65f77293b82f9dfae1aeb Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 1 Oct 2021 13:46:20 -0400 Subject: [PATCH] Add Icons to IRole (#204) * Added icon field to IRole * Added GetGuildRoleIconUrl() --- src/Discord.Net.Core/CDN.cs | 10 +++++++ src/Discord.Net.Core/Discord.Net.Core.xml | 26 +++++++++++++++++++ src/Discord.Net.Core/Entities/Roles/IRole.cs | 15 +++++++++++ src/Discord.Net.Rest/API/Common/Role.cs | 2 ++ src/Discord.Net.Rest/Discord.Net.Rest.xml | 6 +++++ .../Entities/Roles/RestRole.cs | 7 +++++ .../Discord.Net.WebSocket.xml | 6 +++++ .../Entities/Roles/SocketRole.cs | 7 +++++ 8 files changed, 79 insertions(+) diff --git a/src/Discord.Net.Core/CDN.cs b/src/Discord.Net.Core/CDN.cs index 78fba574f..b170336dc 100644 --- a/src/Discord.Net.Core/CDN.cs +++ b/src/Discord.Net.Core/CDN.cs @@ -86,6 +86,16 @@ namespace Discord public static string GetGuildIconUrl(ulong guildId, string iconId) => iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; /// + /// Returns a guild role's icon URL. + /// + /// The role identifier. + /// The icon hash. + /// + /// A URL pointing to the guild role's icon. + /// + public static string GetGuildRoleIconUrl(ulong roleId, string roleHash) + => roleHash != null ? $"{DiscordConfig.CDNUrl}role-icons/{roleId}/{roleHash}.png" : null; + /// /// Returns a guild splash URL. /// /// The guild snowflake identifier. diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index d748671c0..30e0a417f 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -131,6 +131,16 @@ A URL pointing to the guild's icon. + + + Returns a guild role's icon URL. + + The role identifier. + The icon hash. + + A URL pointing to the guild role's icon. + + Returns a guild splash URL. @@ -9646,6 +9656,14 @@ A string containing the name of this role. + + + Gets the icon of this role. + + + A string containing the hash of this role's icon. + + Gets the permissions granted to members of this role. @@ -9684,6 +9702,14 @@ A task that represents the asynchronous modification operation. + + + Gets the image url of the icon role. + + + An image url of the icon role. + + Properties that are used to reorder an . diff --git a/src/Discord.Net.Core/Entities/Roles/IRole.cs b/src/Discord.Net.Core/Entities/Roles/IRole.cs index c02322be9..c9e7ffef7 100644 --- a/src/Discord.Net.Core/Entities/Roles/IRole.cs +++ b/src/Discord.Net.Core/Entities/Roles/IRole.cs @@ -52,6 +52,13 @@ namespace Discord /// string Name { get; } /// + /// Gets the icon of this role. + /// + /// + /// A string containing the hash of this role's icon. + /// + string Icon { get; } + /// /// Gets the permissions granted to members of this role. /// /// @@ -86,5 +93,13 @@ namespace Discord /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); + + /// + /// Gets the image url of the icon role. + /// + /// + /// An image url of the icon role. + /// + string GetIconUrl(); } } diff --git a/src/Discord.Net.Rest/API/Common/Role.cs b/src/Discord.Net.Rest/API/Common/Role.cs index 4c33956af..09fb99885 100644 --- a/src/Discord.Net.Rest/API/Common/Role.cs +++ b/src/Discord.Net.Rest/API/Common/Role.cs @@ -8,6 +8,8 @@ namespace Discord.API public ulong Id { get; set; } [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("icon")] + public string Icon { get; set; } [JsonProperty("color")] public uint Color { get; set; } [JsonProperty("hoist")] diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.xml b/src/Discord.Net.Rest/Discord.Net.Rest.xml index 91727936d..78789b51e 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.xml +++ b/src/Discord.Net.Rest/Discord.Net.Rest.xml @@ -4613,6 +4613,9 @@ + + + @@ -4639,6 +4642,9 @@ + + + diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index 69a2abe20..8866fd282 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -24,6 +24,8 @@ namespace Discord.Rest /// public string Name { get; private set; } /// + public string Icon { get; private set; } + /// public GuildPermissions Permissions { get; private set; } /// public int Position { get; private set; } @@ -53,6 +55,7 @@ namespace Discord.Rest internal void Update(Model model) { Name = model.Name; + Icon = model.Icon; IsHoisted = model.Hoist; IsManaged = model.Managed; IsMentionable = model.Mentionable; @@ -73,6 +76,10 @@ namespace Discord.Rest public Task DeleteAsync(RequestOptions options = null) => RoleHelper.DeleteAsync(this, Discord, options); + /// + public string GetIconUrl() + => CDN.GetGuildRoleIconUrl(Id, Icon); + /// public int CompareTo(IRole role) => RoleUtils.Compare(this, role); diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index abf0c1bb2..ea9937cd1 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -4843,6 +4843,9 @@ + + + @@ -4877,6 +4880,9 @@ + + + Gets the name of the role. diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index d9740338f..40dc057cd 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -34,6 +34,8 @@ namespace Discord.WebSocket /// public string Name { get; private set; } /// + public string Icon { get; private set; } + /// public GuildPermissions Permissions { get; private set; } /// public int Position { get; private set; } @@ -72,6 +74,7 @@ namespace Discord.WebSocket internal void Update(ClientState state, Model model) { Name = model.Name; + Icon = model.Icon; IsHoisted = model.Hoist; IsManaged = model.Managed; IsMentionable = model.Mentionable; @@ -89,6 +92,10 @@ namespace Discord.WebSocket public Task DeleteAsync(RequestOptions options = null) => RoleHelper.DeleteAsync(this, Discord, options); + /// + public string GetIconUrl() + => CDN.GetGuildRoleIconUrl(Id, Icon); + /// /// Gets the name of the role. ///