From 1c63fd479dfd0cacf204101a51284c4d2fc1ae85 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Fri, 29 Nov 2019 18:59:11 -0800 Subject: [PATCH] (ifcbrk)fix: #1335 Add isMentionable parameter to CreateRoleAsync in non-breaking manner (#1418) * Fix #1335 Add isMentionable parameter to CreateRoleAsync in non-breaking manner This PR adds the isMentionable parameter to the CreateRoleAsync method in a way that prevents it from being interface-breaking. This has been done by adding it as an optional parameter at the end of publicly-exposed methods. This parameter determines if the newly created role can be mentioned as it is created. * Overload CreateRoleAsync methods --- src/Discord.Net.Core/Entities/Guilds/IGuild.cs | 15 +++++++++++++++ .../Entities/Guilds/GuildHelper.cs | 3 ++- src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs | 15 ++++++++++++--- .../Entities/Guilds/SocketGuild.cs | 14 +++++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 213091ad4..a18e91b69 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -598,6 +598,21 @@ namespace Discord /// role. /// Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null); + // TODO remove CreateRoleAsync overload that does not have isMentionable when breaking change is acceptable + /// + /// Creates a new role with the provided name. + /// + /// The new name for the role. + /// The guild permission that the role should possess. + /// The color of the role. + /// Whether the role is separated from others on the sidebar. + /// Whether the role can be mentioned. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the newly created + /// role. + /// + Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, bool isMentionable = false, RequestOptions options = null); /// /// Adds a user to this guild. diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 7730a9cc3..664c57a1c 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -257,7 +257,7 @@ namespace Discord.Rest //Roles /// is null. public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client, - string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) + string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) { if (name == null) throw new ArgumentNullException(paramName: nameof(name)); @@ -270,6 +270,7 @@ namespace Discord.Rest x.Permissions = (permissions ?? role.Permissions); x.Color = (color ?? Color.Default); x.Hoist = isHoisted; + x.Mentionable = isMentionable; }, options).ConfigureAwait(false); return role; diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index e9e4d3290..900f5045e 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -530,6 +530,11 @@ namespace Discord.Rest return null; } + /// + public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), + bool isHoisted = false, RequestOptions options = null) + => CreateRoleAsync(name, permissions, color, isHoisted, false, options); + /// /// Creates a new role with the provided name. /// @@ -538,14 +543,15 @@ namespace Discord.Rest /// The color of the role. /// Whether the role is separated from others on the sidebar. /// The options to be used when sending the request. + /// Whether the role can be mentioned. /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// role. /// public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), - bool isHoisted = false, RequestOptions options = null) + bool isHoisted = false, bool isMentionable = false, RequestOptions options = null) { - var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false); + var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); _roles = _roles.Add(role.Id, role); return role; } @@ -833,7 +839,10 @@ namespace Discord.Rest => GetRole(id); /// async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) - => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); + => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false); + /// + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) + => await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); /// async Task IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action func, RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 054348ef1..da9a316eb 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -679,6 +679,10 @@ namespace Discord.WebSocket return null; } + /// + public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), + bool isHoisted = false, RequestOptions options = null) + => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, false, options); /// /// Creates a new role with the provided name. /// @@ -686,6 +690,7 @@ namespace Discord.WebSocket /// The guild permission that the role should possess. /// The color of the role. /// Whether the role is separated from others on the sidebar. + /// Whether the role can be mentioned. /// The options to be used when sending the request. /// is null. /// @@ -693,8 +698,8 @@ namespace Discord.WebSocket /// role. /// public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), - bool isHoisted = false, RequestOptions options = null) - => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); + bool isHoisted = false, bool isMentionable = false, RequestOptions options = null) + => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options); internal SocketRole AddRole(RoleModel model) { var role = SocketRole.Create(this, Discord.State, model); @@ -1151,7 +1156,10 @@ namespace Discord.WebSocket => GetRole(id); /// async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) - => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); + => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false); + /// + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) + => await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); /// Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)