* Implemented include_roles for guilds/id/prune get&post * Unnecessary using Co-authored-by: Paulo <pnmanjos@hotmail.com>tags/2.3.0
| @@ -705,11 +705,12 @@ namespace Discord | |||||
| /// <param name="days">The number of days required for the users to be kicked.</param> | /// <param name="days">The number of days required for the users to be kicked.</param> | ||||
| /// <param name="simulate">Whether this prune action is a simulation.</param> | /// <param name="simulate">Whether this prune action is a simulation.</param> | ||||
| /// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
| /// <param name="includeRoleIds">An array of role IDs to be included in the prune of users who do not have any additional roles.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents the asynchronous prune operation. The task result contains the number of users to | /// A task that represents the asynchronous prune operation. The task result contains the number of users to | ||||
| /// be or has been removed from this guild. | /// be or has been removed from this guild. | ||||
| /// </returns> | /// </returns> | ||||
| Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); | |||||
| Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null); | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets a collection of users in this guild that the name or nickname starts with the | /// Gets a collection of users in this guild that the name or nickname starts with the | ||||
| /// provided <see cref="string"/> at <paramref name="query"/>. | /// provided <see cref="string"/> at <paramref name="query"/>. | ||||
| @@ -9,9 +9,13 @@ namespace Discord.API.Rest | |||||
| [JsonProperty("days")] | [JsonProperty("days")] | ||||
| public int Days { get; } | public int Days { get; } | ||||
| public GuildPruneParams(int days) | |||||
| [JsonProperty("include_roles")] | |||||
| public ulong[] IncludeRoleIds { get; } | |||||
| public GuildPruneParams(int days, ulong[] includeRoleIds) | |||||
| { | { | ||||
| Days = days; | Days = days; | ||||
| IncludeRoleIds = includeRoleIds; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -853,10 +853,11 @@ namespace Discord.API | |||||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | Preconditions.NotEqual(guildId, 0, nameof(guildId)); | ||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| Preconditions.AtLeast(args.Days, 1, nameof(args.Days)); | Preconditions.AtLeast(args.Days, 1, nameof(args.Days)); | ||||
| string endpointRoleIds = args.IncludeRoleIds?.Length > 0 ? $"&include_roles={string.Join(",", args.IncludeRoleIds)}" : ""; | |||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var ids = new BucketIds(guildId: guildId); | var ids = new BucketIds(guildId: guildId); | ||||
| return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}", ids, options: options).ConfigureAwait(false); | |||||
| return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); | |||||
| } | } | ||||
| //Guild Bans | //Guild Bans | ||||
| @@ -404,9 +404,9 @@ namespace Discord.Rest | |||||
| ); | ); | ||||
| } | } | ||||
| public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client, | public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client, | ||||
| int days, bool simulate, RequestOptions options) | |||||
| int days, bool simulate, RequestOptions options, IEnumerable<ulong> includeRoleIds) | |||||
| { | { | ||||
| var args = new GuildPruneParams(days); | |||||
| var args = new GuildPruneParams(days, includeRoleIds?.ToArray()); | |||||
| GetGuildPruneCountResponse model; | GetGuildPruneCountResponse model; | ||||
| if (simulate) | if (simulate) | ||||
| model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false); | model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
| @@ -479,7 +479,7 @@ namespace Discord.Rest | |||||
| var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false); | var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false); | ||||
| return emote.ToEntity(); | return emote.ToEntity(); | ||||
| } | } | ||||
| public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles, | |||||
| public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles, | |||||
| RequestOptions options) | RequestOptions options) | ||||
| { | { | ||||
| var apiargs = new CreateGuildEmoteParams | var apiargs = new CreateGuildEmoteParams | ||||
| @@ -494,7 +494,7 @@ namespace Discord.Rest | |||||
| return emote.ToEntity(); | return emote.ToEntity(); | ||||
| } | } | ||||
| /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | ||||
| public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, | |||||
| public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, | |||||
| RequestOptions options) | RequestOptions options) | ||||
| { | { | ||||
| if (func == null) throw new ArgumentNullException(paramName: nameof(func)); | if (func == null) throw new ArgumentNullException(paramName: nameof(func)); | ||||
| @@ -512,7 +512,7 @@ namespace Discord.Rest | |||||
| var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false); | var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false); | ||||
| return emote.ToEntity(); | return emote.ToEntity(); | ||||
| } | } | ||||
| public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | |||||
| public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | |||||
| => client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options); | => client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options); | ||||
| } | } | ||||
| } | } | ||||
| @@ -205,7 +205,7 @@ namespace Discord.Rest | |||||
| role?.Update(model); | role?.Update(model); | ||||
| } | } | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public Task LeaveAsync(RequestOptions options = null) | public Task LeaveAsync(RequestOptions options = null) | ||||
| => GuildHelper.LeaveAsync(this, Discord, options); | => GuildHelper.LeaveAsync(this, Discord, options); | ||||
| @@ -631,8 +631,8 @@ namespace Discord.Rest | |||||
| /// A task that represents the asynchronous prune operation. The task result contains the number of users to | /// A task that represents the asynchronous prune operation. The task result contains the number of users to | ||||
| /// be or has been removed from this guild. | /// be or has been removed from this guild. | ||||
| /// </returns> | /// </returns> | ||||
| public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) | |||||
| => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); | |||||
| public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null) | |||||
| => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options, includeRoleIds); | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets a collection of users in this guild that the name or nickname starts with the | /// Gets a collection of users in this guild that the name or nickname starts with the | ||||
| @@ -746,8 +746,8 @@ namespace Discord.WebSocket | |||||
| return null; | return null; | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) | |||||
| => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); | |||||
| public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null) | |||||
| => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options, includeRoleIds); | |||||
| internal SocketGuildUser AddOrUpdateUser(UserModel model) | internal SocketGuildUser AddOrUpdateUser(UserModel model) | ||||
| { | { | ||||