@@ -1,4 +1,4 @@ | |||
using Discord.Audio; | |||
using Discord.Audio; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Threading.Tasks; | |||
@@ -66,6 +66,24 @@ namespace Discord | |||
/// <summary> Gets a collection of all users banned on this guild. </summary> | |||
Task<IReadOnlyCollection<IBan>> GetBansAsync(RequestOptions options = null); | |||
/// <summary> | |||
/// Gets a ban object for a banned user. | |||
/// </summary> | |||
/// <param name="user">The banned user.</param> | |||
/// <returns> | |||
/// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||
/// reason for the ban; <see langword="null"/> if the ban entry cannot be found. | |||
/// </returns> | |||
Task<IBan> GetBanAsync(IUser user, RequestOptions options = null); | |||
/// <summary> | |||
/// Gets a ban object for a banned user. | |||
/// </summary> | |||
/// <param name="userId">The snowflake identifier for the banned user.</param> | |||
/// <returns> | |||
/// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||
/// reason for the ban; <see langword="null"/> if the ban entry cannot be found. | |||
/// </returns> | |||
Task<IBan> GetBanAsync(ulong userId, RequestOptions options = null); | |||
/// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary> | |||
/// <param name="pruneDays">The number of days to remove messages from this user for - must be between [0, 7]</param> | |||
Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null); | |||
@@ -135,4 +153,4 @@ namespace Discord | |||
/// <summary> Deletes an existing emote from this guild. </summary> | |||
Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null); | |||
} | |||
} | |||
} |
@@ -800,6 +800,15 @@ namespace Discord.API | |||
var ids = new BucketIds(guildId: guildId); | |||
return await SendAsync<IReadOnlyCollection<Ban>>("GET", () => $"guilds/{guildId}/bans", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task<Ban> GetGuildBanAsync(ulong guildId, ulong userId, RequestOptions options) | |||
{ | |||
Preconditions.NotEqual(userId, 0, nameof(userId)); | |||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
options = RequestOptions.CreateOrClone(options); | |||
var ids = new BucketIds(guildId: guildId); | |||
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
@@ -1,4 +1,4 @@ | |||
using Discord.API.Rest; | |||
using Discord.API.Rest; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.Immutable; | |||
@@ -111,6 +111,11 @@ namespace Discord.Rest | |||
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false); | |||
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray(); | |||
} | |||
public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) | |||
{ | |||
var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); | |||
return RestBan.Create(client, model); | |||
} | |||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, | |||
ulong userId, int pruneDays, string reason, RequestOptions options) | |||
@@ -1,4 +1,4 @@ | |||
using Discord.Audio; | |||
using Discord.Audio; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.Immutable; | |||
@@ -140,6 +140,10 @@ namespace Discord.Rest | |||
//Bans | |||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | |||
=> GuildHelper.GetBansAsync(this, Discord, options); | |||
public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null) | |||
=> GuildHelper.GetBanAsync(this, Discord, user.Id, options); | |||
public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null) | |||
=> GuildHelper.GetBanAsync(this, Discord, userId, options); | |||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | |||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | |||
@@ -291,6 +295,12 @@ namespace Discord.Rest | |||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | |||
=> await GetBansAsync(options).ConfigureAwait(false); | |||
/// <inheritdoc/> | |||
async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options) | |||
=> await GetBanAsync(user, options).ConfigureAwait(false); | |||
/// <inheritdoc/> | |||
async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options) | |||
=> await GetBanAsync(userId, options).ConfigureAwait(false); | |||
async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | |||
{ | |||
@@ -288,6 +288,10 @@ namespace Discord.WebSocket | |||
//Bans | |||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | |||
=> GuildHelper.GetBansAsync(this, Discord, options); | |||
public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null) | |||
=> GuildHelper.GetBanAsync(this, Discord, user.Id, options); | |||
public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null) | |||
=> GuildHelper.GetBanAsync(this, Discord, userId, options); | |||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | |||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | |||
@@ -641,6 +645,12 @@ namespace Discord.WebSocket | |||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | |||
=> await GetBansAsync(options).ConfigureAwait(false); | |||
/// <inheritdoc/> | |||
async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options) | |||
=> await GetBanAsync(user, options).ConfigureAwait(false); | |||
/// <inheritdoc/> | |||
async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options) | |||
=> await GetBanAsync(userId, options).ConfigureAwait(false); | |||
Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | |||
=> Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels); | |||