| @@ -28,5 +28,16 @@ namespace Discord | |||||
| Task KickAsync(RequestOptions options = null); | Task KickAsync(RequestOptions options = null); | ||||
| /// <summary> Modifies this user's properties in this guild. </summary> | /// <summary> Modifies this user's properties in this guild. </summary> | ||||
| Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null); | Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null); | ||||
| ///<summary> Adds roles to this user in this guild. </summary> | |||||
| Task AddRolesAsync(params IRole[] roles); | |||||
| ///<summary> Adds roles to this user in this guild. </summary> | |||||
| Task AddRolesAsync(IEnumerable<IRole> roles); | |||||
| ///<summary> Removes roles from this user in this guild. </summary> | |||||
| Task RemoveRolesAsync(params IRole[] roles); | |||||
| ///<summary> Removes roles from this user in this guild. </summary> | |||||
| Task RemoveRolesAsync(IEnumerable<IRole> roles); | |||||
| ///<summary> Adds and removes roles from this user in this guild. </summary> | |||||
| Task ChangeRolesAsync(IEnumerable<IRole> add = null, IEnumerable<IRole> remove = 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -82,6 +82,23 @@ namespace Discord.Rest | |||||
| else if (args.RoleIds.IsSpecified) | else if (args.RoleIds.IsSpecified) | ||||
| UpdateRoles(args.RoleIds.Value.ToArray()); | UpdateRoles(args.RoleIds.Value.ToArray()); | ||||
| } | } | ||||
| public Task AddRolesAsync(params IRole[] roles) | |||||
| => ChangeRolesAsync(add: roles); | |||||
| public Task AddRolesAsync(IEnumerable<IRole> roles) | |||||
| => ChangeRolesAsync(add: roles); | |||||
| public Task RemoveRolesAsync(params IRole[] roles) | |||||
| => ChangeRolesAsync(remove: roles); | |||||
| public Task RemoveRolesAsync(IEnumerable<IRole> roles) | |||||
| => ChangeRolesAsync(remove: roles); | |||||
| public async Task ChangeRolesAsync(IEnumerable<IRole> add = null, IEnumerable<IRole> remove = null) | |||||
| { | |||||
| IEnumerable<ulong> roleIds = RoleIds; | |||||
| if (remove != null) | |||||
| roleIds = roleIds.Except(remove.Select(x => x.Id)); | |||||
| if (add != null) | |||||
| roleIds = roleIds.Concat(add.Select(x => x.Id)); | |||||
| await ModifyAsync(x => x.RoleIds = roleIds.ToArray()).ConfigureAwait(false); | |||||
| } | |||||
| public Task KickAsync(RequestOptions options = null) | public Task KickAsync(RequestOptions options = null) | ||||
| => UserHelper.KickAsync(this, Discord, options); | => UserHelper.KickAsync(this, Discord, options); | ||||
| @@ -107,6 +107,23 @@ namespace Discord.WebSocket | |||||
| => UserHelper.ModifyAsync(this, Discord, func, options); | => UserHelper.ModifyAsync(this, Discord, func, options); | ||||
| public Task KickAsync(RequestOptions options = null) | public Task KickAsync(RequestOptions options = null) | ||||
| => UserHelper.KickAsync(this, Discord, options); | => UserHelper.KickAsync(this, Discord, options); | ||||
| public Task AddRolesAsync(params IRole[] roles) | |||||
| => ChangeRolesAsync(add: roles); | |||||
| public Task AddRolesAsync(IEnumerable<IRole> roles) | |||||
| => ChangeRolesAsync(add: roles); | |||||
| public Task RemoveRolesAsync(params IRole[] roles) | |||||
| => ChangeRolesAsync(remove: roles); | |||||
| public Task RemoveRolesAsync(IEnumerable<IRole> roles) | |||||
| => ChangeRolesAsync(remove: roles); | |||||
| public async Task ChangeRolesAsync(IEnumerable<IRole> add = null, IEnumerable<IRole> remove = null) | |||||
| { | |||||
| IEnumerable<ulong> roleIds = _roleIds; | |||||
| if (remove != null) | |||||
| roleIds = roleIds.Except(remove.Select(x => x.Id)); | |||||
| if (add != null) | |||||
| roleIds = roleIds.Concat(add.Select(x => x.Id)); | |||||
| await ModifyAsync(x => x.RoleIds = roleIds.ToArray()).ConfigureAwait(false); | |||||
| } | |||||
| public ChannelPermissions GetPermissions(IGuildChannel channel) | public ChannelPermissions GetPermissions(IGuildChannel channel) | ||||
| => new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue)); | => new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue)); | ||||