| @@ -1,9 +1,13 @@ | |||||
| #pragma warning disable CS1591 | #pragma warning disable CS1591 | ||||
| using Newtonsoft.Json; | |||||
| namespace Discord.API | namespace Discord.API | ||||
| { | { | ||||
| public class Ban | public class Ban | ||||
| { | { | ||||
| [JsonProperty("user")] | |||||
| public User User { get; set; } | public User User { get; set; } | ||||
| [JsonProperty("reason")] | |||||
| public string Reason { get; set; } | public string Reason { get; set; } | ||||
| } | } | ||||
| } | } | ||||
| @@ -440,11 +440,11 @@ namespace Discord.API | |||||
| } | } | ||||
| //Guild Bans | //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)); | 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) | public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) | ||||
| { | { | ||||
| @@ -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}"; | |||||
| } | |||||
| } | |||||
| @@ -61,7 +61,7 @@ namespace Discord | |||||
| Task LeaveAsync(); | Task LeaveAsync(); | ||||
| /// <summary> Gets a collection of all users banned on this guild. </summary> | /// <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> | /// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary> | ||||
| Task AddBanAsync(IUser user, int pruneDays = 0); | Task AddBanAsync(IUser user, int pruneDays = 0); | ||||
| /// <summary> Bans the provided user id from this guild and optionally prunes their recent messages. </summary> | /// <summary> Bans the provided user id from this guild and optionally prunes their recent messages. </summary> | ||||
| @@ -157,10 +157,10 @@ namespace Discord | |||||
| await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); | 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); | 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 Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); | ||||
| public async Task AddBanAsync(ulong userId, int pruneDays = 0) | public async Task AddBanAsync(ulong userId, int pruneDays = 0) | ||||