Added Server.GetBans

This commit is contained in:
RogueException
2015-12-27 15:28:34 -04:00
parent 33a2e1858d
commit 51fd771af9
3 changed files with 34 additions and 0 deletions

View File

@@ -278,6 +278,9 @@
<Compile Include="..\Discord.Net\API\Client\Rest\Gateway.cs">
<Link>API\Client\Rest\Gateway.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\GetBans.cs">
<Link>API\Client\Rest\GetBans.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\GetInvite.cs">
<Link>API\Client\Rest\GetInvite.cs</Link>
</Compile>

View File

@@ -0,0 +1,20 @@
using Newtonsoft.Json;
namespace Discord.API.Client.Rest
{
[JsonObject(MemberSerialization.OptIn)]
public sealed class GetBansRequest : IRestRequest<UserReference[]>
{
string IRestRequest.Method => "GET";
string IRestRequest.Endpoint => $"guilds/{GuildId}/bans";
object IRestRequest.Payload => null;
bool IRestRequest.IsPrivate => false;
public ulong GuildId { get; }
public GetBansRequest(ulong guildId)
{
GuildId = guildId;
}
}
}

View File

@@ -172,6 +172,17 @@ namespace Discord
}
#region Bans
public async Task<IEnumerable<User>> GetBans()
{
var response = await Client.ClientAPI.Send(new GetBansRequest(Id)).ConfigureAwait(false);
return response.Select(x =>
{
var user = new User(Client, x.Id, this);
user.Update(x);
return user;
});
}
public Task Ban(User user, int pruneDays = 0)
{
var request = new AddGuildBanRequest(user.Server.Id, user.Id)