Browse Source

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.
pull/1418/head
Chris Johnston 5 years ago
parent
commit
df4ee16fbf
4 changed files with 15 additions and 10 deletions
  1. +3
    -1
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  2. +2
    -1
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  3. +5
    -4
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  4. +5
    -4
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

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

@@ -593,11 +593,13 @@ namespace Discord
/// <param name="color">The color of the role.</param> /// <param name="color">The color of the role.</param>
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> /// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param>
/// <param name="options">The options to be used when sending the request.</param> /// <param name="options">The options to be used when sending the request.</param>
/// <param name="isMentionable">Whether the role can be mentioned.</param>
/// <returns> /// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created /// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role. /// role.
/// </returns> /// </returns>
Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null);
Task<IRole> 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


/// <summary> /// <summary>
/// Adds a user to this guild. /// Adds a user to this guild.


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

@@ -257,7 +257,7 @@ namespace Discord.Rest
//Roles //Roles
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestRole> 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)); if (name == null) throw new ArgumentNullException(paramName: nameof(name));


@@ -270,6 +270,7 @@ namespace Discord.Rest
x.Permissions = (permissions ?? role.Permissions); x.Permissions = (permissions ?? role.Permissions);
x.Color = (color ?? Color.Default); x.Color = (color ?? Color.Default);
x.Hoist = isHoisted; x.Hoist = isHoisted;
x.Mentionable = isMentionable;
}, options).ConfigureAwait(false); }, options).ConfigureAwait(false);


return role; return role;


+ 5
- 4
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -538,14 +538,15 @@ namespace Discord.Rest
/// <param name="color">The color of the role.</param> /// <param name="color">The color of the role.</param>
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> /// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param>
/// <param name="options">The options to be used when sending the request.</param> /// <param name="options">The options to be used when sending the request.</param>
/// <param name="isMentionable">Whether the role can be mentioned.</param>
/// <returns> /// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created /// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role. /// role.
/// </returns> /// </returns>
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), public async Task<RestRole> 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); _roles = _roles.Add(role.Id, role);
return role; return role;
} }
@@ -832,8 +833,8 @@ namespace Discord.Rest
IRole IGuild.GetRole(ulong id) IRole IGuild.GetRole(ulong id)
=> GetRole(id); => GetRole(id);
/// <inheritdoc /> /// <inheritdoc />
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options, bool isMentionable)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options, isMentionable).ConfigureAwait(false);


/// <inheritdoc /> /// <inheritdoc />
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options)


+ 5
- 4
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -687,14 +687,15 @@ namespace Discord.WebSocket
/// <param name="color">The color of the role.</param> /// <param name="color">The color of the role.</param>
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> /// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param>
/// <param name="options">The options to be used when sending the request.</param> /// <param name="options">The options to be used when sending the request.</param>
/// <param name="isMentionable">Whether the role can be mentioned.</param>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
/// <returns> /// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created /// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role. /// role.
/// </returns> /// </returns>
public Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), public Task<RestRole> 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) internal SocketRole AddRole(RoleModel model)
{ {
var role = SocketRole.Create(this, Discord.State, model); var role = SocketRole.Create(this, Discord.State, model);
@@ -1150,8 +1151,8 @@ namespace Discord.WebSocket
IRole IGuild.GetRole(ulong id) IRole IGuild.GetRole(ulong id)
=> GetRole(id); => GetRole(id);
/// <inheritdoc /> /// <inheritdoc />
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options, bool isMentionable)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options, isMentionable).ConfigureAwait(false);


/// <inheritdoc /> /// <inheritdoc />
Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)


Loading…
Cancel
Save