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:
Mateusz Brawański
2017-03-18 12:54:49 +01:00
committed by RogueException
parent 11ba30c6fa
commit efbd3cb681
7 changed files with 70 additions and 31 deletions

View File

@@ -84,6 +84,18 @@ namespace Discord.Rest
}
public Task KickAsync(RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, options);
/// <inheritdoc />
public Task AddRoleAsync(IRole role, RequestOptions options = null)
=> AddRolesAsync(new[] { role }, options);
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.AddRolesAsync(this, Discord, roles, options);
/// <inheritdoc />
public Task RemoveRoleAsync(IRole role, RequestOptions options = null)
=> RemoveRolesAsync(new[] { role }, options);
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roles, options);
public ChannelPermissions GetPermissions(IGuildChannel channel)
{

View File

@@ -1,5 +1,6 @@
using Discord.API.Rest;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Model = Discord.API.User;
using ImageModel = Discord.API.Image;
@@ -63,5 +64,17 @@ namespace Discord.Rest
var args = new CreateDMChannelParams(user.Id);
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options).ConfigureAwait(false));
}
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
{
foreach (var role in roles)
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options);
}
public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
{
foreach (var role in roles)
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options);
}
}
}