Browse Source

Removed GuildUserExtensions and moved the methods to IGuildUser and implementations

pull/540/head
Emzi0767 8 years ago
parent
commit
b6be009173
4 changed files with 45 additions and 27 deletions
  1. +11
    -0
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  2. +0
    -27
      src/Discord.Net.Core/Extensions/GuildUserExtensions.cs
  3. +17
    -0
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  4. +17
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs

+ 11
- 0
src/Discord.Net.Core/Entities/Users/IGuildUser.cs View File

@@ -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);
} }
} }

+ 0
- 27
src/Discord.Net.Core/Extensions/GuildUserExtensions.cs View File

@@ -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);
}
}
}

+ 17
- 0
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -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);




+ 17
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -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));


Loading…
Cancel
Save