(ifcbrk) feature: Add includeRoleIds to PruneUsersAsync (#1581)

* Implemented include_roles for guilds/id/prune get&post

* Unnecessary using

Co-authored-by: Paulo <pnmanjos@hotmail.com>
This commit is contained in:
Radka Gustavsson
2020-11-07 19:55:14 +01:00
committed by GitHub
parent 971d519e35
commit a80e5ff940
6 changed files with 19 additions and 13 deletions

View File

@@ -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"/>.

View File

@@ -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;
} }
} }
} }

View File

@@ -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

View File

@@ -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);

View File

@@ -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) public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); => 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

View File

@@ -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) public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options, includeRoleIds);
internal SocketGuildUser AddOrUpdateUser(UserModel model) internal SocketGuildUser AddOrUpdateUser(UserModel model)
{ {