From df4ee16fbf76ba25a35dd581c9cb130d077e9097 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Tue, 12 Nov 2019 23:45:24 -0800 Subject: [PATCH] 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. --- src/Discord.Net.Core/Entities/Guilds/IGuild.cs | 4 +++- src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs | 3 ++- src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs | 9 +++++---- src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs | 9 +++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 213091ad4..bb8088b5b 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -593,11 +593,13 @@ namespace Discord /// 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. /// - Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null); + Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null, bool isMentionable = false); + // TODO Chris-Johnston: 3.x breaking interface change: re-order isMentionable parameter /// /// 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..48a532e13 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -538,14 +538,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, RequestOptions options = null, bool isMentionable = false) { - 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; } @@ -832,8 +833,8 @@ namespace Discord.Rest IRole IGuild.GetRole(ulong id) => 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); + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options, bool isMentionable) + => await CreateRoleAsync(name, permissions, color, isHoisted, options, isMentionable).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..cf44e3506 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -687,14 +687,15 @@ namespace Discord.WebSocket /// 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. /// is null. /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// 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, RequestOptions options = null, bool isMentionable = false) + => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options); internal SocketRole AddRole(RoleModel model) { var role = SocketRole.Create(this, Discord.State, model); @@ -1150,8 +1151,8 @@ namespace Discord.WebSocket IRole IGuild.GetRole(ulong id) => 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); + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options, bool isMentionable) + => await CreateRoleAsync(name, permissions, color, isHoisted, options, isMentionable).ConfigureAwait(false); /// Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)