Added REST Ban model

This commit is contained in:
RogueException
2016-08-09 17:20:46 -03:00
parent eff995a2a6
commit b13b52a1c4
5 changed files with 29 additions and 5 deletions

View File

@@ -1,9 +1,13 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API
{
public class Ban
{
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("reason")]
public string Reason { get; set; }
}
}

View File

@@ -440,11 +440,11 @@ namespace Discord.API
}
//Guild Bans
public async Task<IReadOnlyCollection<User>> GetGuildBansAsync(ulong guildId, RequestOptions options = null)
public async Task<IReadOnlyCollection<Ban>> GetGuildBansAsync(ulong guildId, RequestOptions options = null)
{
Preconditions.NotEqual(guildId, 0, nameof(guildId));
return await SendAsync<IReadOnlyCollection<User>>("GET", $"guilds/{guildId}/bans", options: options).ConfigureAwait(false);
return await SendAsync<IReadOnlyCollection<Ban>>("GET", $"guilds/{guildId}/bans", options: options).ConfigureAwait(false);
}
public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null)
{

View File

@@ -0,0 +1,20 @@
using System.Diagnostics;
namespace Discord
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct Ban
{
public IUser User { get; }
public string Reason { get; }
public Ban(IUser user, string reason)
{
User = user;
Reason = reason;
}
public override string ToString() => User.ToString();
private string DebuggerDisplay => $"{User}: {Reason}";
}
}

View File

@@ -61,7 +61,7 @@ namespace Discord
Task LeaveAsync();
/// <summary> Gets a collection of all users banned on this guild. </summary>
Task<IReadOnlyCollection<IUser>> GetBansAsync();
Task<IReadOnlyCollection<Ban>> GetBansAsync();
/// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary>
Task AddBanAsync(IUser user, int pruneDays = 0);
/// <summary> Bans the provided user id from this guild and optionally prunes their recent messages. </summary>

View File

@@ -157,10 +157,10 @@ namespace Discord
await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false);
}
public async Task<IReadOnlyCollection<IUser>> GetBansAsync()
public async Task<IReadOnlyCollection<Ban>> GetBansAsync()
{
var models = await Discord.ApiClient.GetGuildBansAsync(Id).ConfigureAwait(false);
return models.Select(x => new User(x)).ToImmutableArray();
return models.Select(x => new Ban(new User(x.User), x.Reason)).ToImmutableArray();
}
public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays);
public async Task AddBanAsync(ulong userId, int pruneDays = 0)