From fc348078996f9c22e80d6fe58621285ee99d9a05 Mon Sep 17 00:00:00 2001 From: Zack Broderson Date: Sat, 23 Jan 2021 23:20:32 -0500 Subject: [PATCH] Add implementation --- .../Entities/Users/IGuildUser.cs | 40 ++++++++++++++++--- .../Entities/Users/RestGuildUser.cs | 16 ++++---- .../Entities/Users/UserHelper.cs | 12 +++--- .../Entities/Users/SocketGuildUser.cs | 16 ++++---- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs index 1035f7a01..492cb9566 100644 --- a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs @@ -113,8 +113,15 @@ namespace Discord /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); - //TODO add docs - Task AddRoleAsync(ulong id, RequestOptions options = null); + /// + /// Adds the specified role to this user in the guild. + /// + /// The role to be added to the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role addition operation. + /// + Task AddRoleAsync(ulong roleId, RequestOptions options = null); /// /// Adds the specified role to this user in the guild. /// @@ -124,7 +131,14 @@ namespace Discord /// A task that represents the asynchronous role addition operation. /// Task AddRoleAsync(IRole role, RequestOptions options = null); - //TODO: Add docs + /// + /// Adds the specified to this user in the guild. + /// + /// The roles to be added to the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role addition operation. + /// Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null); /// /// Adds the specified to this user in the guild. @@ -135,8 +149,15 @@ namespace Discord /// A task that represents the asynchronous role addition operation. /// Task AddRolesAsync(IEnumerable roles, RequestOptions options = null); - //TODO add docs - Task RemoveRoleAsync(ulong id, RequestOptions options = null); + /// + /// Removes the specified from this user in the guild. + /// + /// The role to be removed from the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role removal operation. + /// + Task RemoveRoleAsync(ulong roleId, RequestOptions options = null); /// /// Removes the specified from this user in the guild. /// @@ -146,7 +167,14 @@ namespace Discord /// A task that represents the asynchronous role removal operation. /// Task RemoveRoleAsync(IRole role, RequestOptions options = null); - //TODO: Add docs + /// + /// Removes the specified from this user in the guild. + /// + /// The roles to be removed from the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role removal operation. + /// Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null); /// /// Removes the specified from this user in the guild. diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index da573b541..6e6bbe09c 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -113,28 +113,28 @@ namespace Discord.Rest => UserHelper.KickAsync(this, Discord, reason, options); /// public Task AddRoleAsync(ulong roleId, RequestOptions options = null) - => throw new NotImplementedException(); + => AddRolesAsync(new[] { roleId }, options); /// public Task AddRoleAsync(IRole role, RequestOptions options = null) - => AddRolesAsync(new[] { role }, options); + => AddRoleAsync(role.Id, options); /// public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) - => throw new NotImplementedException(); + => UserHelper.AddRolesAsync(this, Discord, roleIds, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.AddRolesAsync(this, Discord, roles, options); + => AddRolesAsync(roles.Select(x => x.Id), options); /// public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) - => throw new NotImplementedException(); + => RemoveRolesAsync(new[] { roleId }, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) - => RemoveRolesAsync(new[] { role }, options); + => RemoveRoleAsync(role.Id, options); /// public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) - => throw new NotImplementedException(); + => UserHelper.RemoveRolesAsync(this, Discord, roleIds, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.RemoveRolesAsync(this, Discord, roles, options); + => RemoveRolesAsync(roles.Select(x => x.Id)); /// /// Resolving permissions requires the parent guild to be downloaded. diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index 58e8cd417..3a19fcfc1 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -73,16 +73,16 @@ namespace Discord.Rest return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options).ConfigureAwait(false)); } - public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options) + public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roleIds, RequestOptions options) { - foreach (var role in roles) - await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false); + foreach (var roleId in roleIds) + await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false); } - public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options) + public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roleIds, RequestOptions options) { - foreach (var role in roles) - await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false); + foreach (var roleId in roleIds) + await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index afb2b4fa3..9263fe642 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -178,28 +178,28 @@ namespace Discord.WebSocket => UserHelper.KickAsync(this, Discord, reason, options); /// public Task AddRoleAsync(ulong roleId, RequestOptions options = null) - => throw new NotImplementedException(); + => AddRolesAsync(new[] { roleId }, options); /// public Task AddRoleAsync(IRole role, RequestOptions options = null) - => AddRolesAsync(new[] { role }, options); + => AddRoleAsync(role.Id, options); /// public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) - => throw new NotImplementedException(); + => UserHelper.AddRolesAsync(this, Discord, roleIds, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.AddRolesAsync(this, Discord, roles, options); + => AddRolesAsync(roles.Select(x => x.Id), options); /// public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) - => throw new NotImplementedException(); + => RemoveRolesAsync(new[] { roleId }, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) - => RemoveRolesAsync(new[] { role }, options); + => RemoveRoleAsync(role.Id, options); /// public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) - => throw new NotImplementedException(); + => UserHelper.RemoveRolesAsync(this, Discord, roleIds, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.RemoveRolesAsync(this, Discord, roles, options); + => RemoveRolesAsync(roles.Select(x => x.Id)); /// public ChannelPermissions GetPermissions(IGuildChannel channel)