Skip to content

Commit

Permalink
Add Icons to IRole (discord-net#204)
Browse files Browse the repository at this point in the history
* Added icon field to IRole

* Added GetGuildRoleIconUrl()
  • Loading branch information
WilliamWelsh authored Oct 1, 2021
1 parent 9b7e3da commit 42b693c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Discord.Net.Core/CDN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public static string GetDefaultUserAvatarUrl(ushort discriminator)
public static string GetGuildIconUrl(ulong guildId, string iconId)
=> iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null;
/// <summary>
/// Returns a guild role's icon URL.
/// </summary>
/// <param name="roleId">The role identifier.</param>
/// <param name="roleHash">The icon hash.</param>
/// <returns>
/// A URL pointing to the guild role's icon.
/// </returns>
public static string GetGuildRoleIconUrl(ulong roleId, string roleHash)
=> roleHash != null ? $"{DiscordConfig.CDNUrl}role-icons/{roleId}/{roleHash}.png" : null;
/// <summary>
/// Returns a guild splash URL.
/// </summary>
/// <param name="guildId">The guild snowflake identifier.</param>
Expand Down
26 changes: 26 additions & 0 deletions src/Discord.Net.Core/Discord.Net.Core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@
A URL pointing to the guild's icon.
</returns>
</member>
<member name="M:Discord.CDN.GetGuildRoleIconUrl(System.UInt64,System.String)">
<summary>
Returns a guild role's icon URL.
</summary>
<param name="roleId">The role identifier.</param>
<param name="roleHash">The icon hash.</param>
<returns>
A URL pointing to the guild role's icon.
</returns>
</member>
<member name="M:Discord.CDN.GetGuildSplashUrl(System.UInt64,System.String)">
<summary>
Returns a guild splash URL.
Expand Down Expand Up @@ -9646,6 +9656,14 @@
A string containing the name of this role.
</returns>
</member>
<member name="P:Discord.IRole.Icon">
<summary>
Gets the icon of this role.
</summary>
<returns>
A string containing the hash of this role's icon.
</returns>
</member>
<member name="P:Discord.IRole.Permissions">
<summary>
Gets the permissions granted to members of this role.
Expand Down Expand Up @@ -9684,6 +9702,14 @@
A task that represents the asynchronous modification operation.
</returns>
</member>
<member name="M:Discord.IRole.GetIconUrl">
<summary>
Gets the image url of the icon role.
</summary>
<returns>
An image url of the icon role.
</returns>
</member>
<member name="T:Discord.ReorderRoleProperties">
<summary>
Properties that are used to reorder an <see cref="T:Discord.IRole"/>.
Expand Down
15 changes: 15 additions & 0 deletions src/Discord.Net.Core/Entities/Roles/IRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable
/// </returns>
string Name { get; }
/// <summary>
/// Gets the icon of this role.
/// </summary>
/// <returns>
/// A string containing the hash of this role's icon.
/// </returns>
string Icon { get; }
/// <summary>
/// Gets the permissions granted to members of this role.
/// </summary>
/// <returns>
Expand Down Expand Up @@ -86,5 +93,13 @@ public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null);

/// <summary>
/// Gets the image url of the icon role.
/// </summary>
/// <returns>
/// An image url of the icon role.
/// </returns>
string GetIconUrl();
}
}
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Common/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal class Role
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")]
Expand Down
6 changes: 6 additions & 0 deletions src/Discord.Net.Rest/Discord.Net.Rest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Discord.Net.Rest/Entities/Roles/RestRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class RestRole : RestEntity<ulong>, IRole
/// <inheritdoc />
public string Name { get; private set; }
/// <inheritdoc />
public string Icon { get; private set; }
/// <inheritdoc />
public GuildPermissions Permissions { get; private set; }
/// <inheritdoc />
public int Position { get; private set; }
Expand Down Expand Up @@ -53,6 +55,7 @@ internal static RestRole Create(BaseDiscordClient discord, IGuild guild, Model m
internal void Update(Model model)
{
Name = model.Name;
Icon = model.Icon;
IsHoisted = model.Hoist;
IsManaged = model.Managed;
IsMentionable = model.Mentionable;
Expand All @@ -73,6 +76,10 @@ public async Task ModifyAsync(Action<RoleProperties> func, RequestOptions option
public Task DeleteAsync(RequestOptions options = null)
=> RoleHelper.DeleteAsync(this, Discord, options);

/// <inheritdoc />
public string GetIconUrl()
=> CDN.GetGuildRoleIconUrl(Id, Icon);

/// <inheritdoc />
public int CompareTo(IRole role) => RoleUtils.Compare(this, role);

Expand Down
6 changes: 6 additions & 0 deletions src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class SocketRole : SocketEntity<ulong>, IRole
/// <inheritdoc />
public string Name { get; private set; }
/// <inheritdoc />
public string Icon { get; private set; }
/// <inheritdoc />
public GuildPermissions Permissions { get; private set; }
/// <inheritdoc />
public int Position { get; private set; }
Expand Down Expand Up @@ -72,6 +74,7 @@ internal static SocketRole Create(SocketGuild guild, ClientState state, Model mo
internal void Update(ClientState state, Model model)
{
Name = model.Name;
Icon = model.Icon;
IsHoisted = model.Hoist;
IsManaged = model.Managed;
IsMentionable = model.Mentionable;
Expand All @@ -89,6 +92,10 @@ public Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = nu
public Task DeleteAsync(RequestOptions options = null)
=> RoleHelper.DeleteAsync(this, Discord, options);

/// <inheritdoc />
public string GetIconUrl()
=> CDN.GetGuildRoleIconUrl(Id, Icon);

/// <summary>
/// Gets the name of the role.
/// </summary>
Expand Down

0 comments on commit 42b693c

Please sign in to comment.