GuildUserExtensions removed in favour of atomic role add/remove endpoints (#540)
* Removed GuildUserExtensions and moved the methods to IGuildUser and implementations * Made changes per fox's suggestion: Change->Modify. New Modify overload. * Oops * Per Volt: reimplemented new endpoints * Fixing broken docstrings * I forgot that docstrings are XML * Implemented atomic add/remove role endpoints * Removed so people aren't irked * Added single-item role add/remove methods
This commit is contained in:
committed by
RogueException
parent
11ba30c6fa
commit
efbd3cb681
@@ -41,16 +41,16 @@ namespace Discord
|
||||
/// What roles should the user have?
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To add a role to a user: <see cref="GuildUserExtensions.AddRolesAsync(IGuildUser, IRole[])"/>
|
||||
/// To remove a role from a user: <see cref="GuildUserExtensions.RemoveRolesAsync(IGuildUser, IRole[])"/>
|
||||
/// To add a role to a user: <see cref="IGuildUser.AddRolesAsync(IEnumerable<IRole>, RequestOptions)"/>
|
||||
/// To remove a role from a user: <see cref="IGuildUser.RemoveRolesAsync(IEnumerable<IRole>, RequestOptions)"/>
|
||||
/// </remarks>
|
||||
public Optional<IEnumerable<IRole>> Roles { get; set; }
|
||||
/// <summary>
|
||||
/// What roles should the user have?
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To add a role to a user: <see cref="GuildUserExtensions.AddRolesAsync(IGuildUser, IRole[])"/>
|
||||
/// To remove a role from a user: <see cref="GuildUserExtensions.RemoveRolesAsync(IGuildUser, IRole[])"/>
|
||||
/// To add a role to a user: <see cref="IGuildUser.AddRolesAsync(IEnumerable<IRole>, RequestOptions)"/>
|
||||
/// To remove a role from a user: <see cref="IGuildUser.RemoveRolesAsync(IEnumerable<IRole>, RequestOptions)"/>
|
||||
/// </remarks>
|
||||
public Optional<IEnumerable<ulong>> RoleIds { get; set; }
|
||||
/// <summary>
|
||||
|
||||
@@ -28,5 +28,14 @@ namespace Discord
|
||||
Task KickAsync(RequestOptions options = null);
|
||||
/// <summary> Modifies this user's properties in this guild. </summary>
|
||||
Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null);
|
||||
|
||||
/// <summary> Adds a role to this user in this guild. </summary>
|
||||
Task AddRoleAsync(IRole role, RequestOptions options = null);
|
||||
/// <summary> Adds roles to this user in this guild. </summary>
|
||||
Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null);
|
||||
/// <summary> Removes a role from this user in this guild. </summary>
|
||||
Task RemoveRoleAsync(IRole role, RequestOptions options = null);
|
||||
/// <summary> Removes roles from this user in this guild. </summary>
|
||||
Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public static class GuildUserExtensions
|
||||
{
|
||||
public static Task AddRolesAsync(this IGuildUser user, params IRole[] roles)
|
||||
=> ChangeRolesAsync(user, add: roles);
|
||||
public static Task AddRolesAsync(this IGuildUser user, IEnumerable<IRole> roles)
|
||||
=> ChangeRolesAsync(user, add: roles);
|
||||
public static Task RemoveRolesAsync(this IGuildUser user, params IRole[] roles)
|
||||
=> ChangeRolesAsync(user, remove: roles);
|
||||
public static Task RemoveRolesAsync(this IGuildUser user, IEnumerable<IRole> roles)
|
||||
=> ChangeRolesAsync(user, remove: roles);
|
||||
public static async Task ChangeRolesAsync(this IGuildUser user, IEnumerable<IRole> add = null, IEnumerable<IRole> remove = null)
|
||||
{
|
||||
IEnumerable<ulong> roleIds = user.RoleIds;
|
||||
if (remove != null)
|
||||
roleIds = roleIds.Except(remove.Select(x => x.Id));
|
||||
if (add != null)
|
||||
roleIds = roleIds.Concat(add.Select(x => x.Id));
|
||||
await user.ModifyAsync(x => x.RoleIds = roleIds.ToArray()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user