Skip to content

Commit

Permalink
(ifcbrk) feature: Add includeRoleIds to PruneUsersAsync (#1581)
Browse files Browse the repository at this point in the history
* Implemented include_roles for guilds/id/prune get&post

* Unnecessary using

Co-authored-by: Paulo <pnmanjos@hotmail.com>
  • Loading branch information
Radka Gustavsson and SubZero0 committed Nov 7, 2020
1 parent 971d519 commit a80e5ff
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,12 @@ public interface IGuild : IDeletable, ISnowflakeEntity
/// <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="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>
/// 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.
/// </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>
/// Gets a collection of users in this guild that the name or nickname starts with the
/// provided <see cref="string"/> at <paramref name="query"/>.
Expand Down
6 changes: 5 additions & 1 deletion src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ internal class GuildPruneParams
[JsonProperty("days")]
public int Days { get; }

public GuildPruneParams(int days)
[JsonProperty("include_roles")]
public ulong[] IncludeRoleIds { get; }

public GuildPruneParams(int days, ulong[] includeRoleIds)
{
Days = days;
IncludeRoleIds = includeRoleIds;
}
}
}
3 changes: 2 additions & 1 deletion src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,11 @@ public async Task<GetGuildPruneCountResponse> GetGuildPruneCountAsync(ulong guil
Preconditions.NotEqual(guildId, 0, nameof(guildId));
Preconditions.NotNull(args, nameof(args));
Preconditions.AtLeast(args.Days, 1, nameof(args.Days));
string endpointRoleIds = args.IncludeRoleIds?.Length > 0 ? $"&include_roles={string.Join(",", args.IncludeRoleIds)}" : "";
options = RequestOptions.CreateOrClone(options);

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
Expand Down
10 changes: 5 additions & 5 deletions src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient cl
);
}
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;
if (simulate)
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false);
Expand Down Expand Up @@ -479,7 +479,7 @@ public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClie
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false);
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)
{
var apiargs = new CreateGuildEmoteParams
Expand All @@ -494,7 +494,7 @@ public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClie
return emote.ToEntity();
}
/// <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)
{
if (func == null) throw new ArgumentNullException(paramName: nameof(func));
Expand All @@ -512,7 +512,7 @@ public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClie
var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false);
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);
}
}
6 changes: 3 additions & 3 deletions src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, Req
role?.Update(model);
}
}

/// <inheritdoc />
public Task LeaveAsync(RequestOptions options = null)
=> GuildHelper.LeaveAsync(this, Discord, options);
Expand Down Expand Up @@ -631,8 +631,8 @@ public Task<RestGuildUser> GetOwnerAsync(RequestOptions options = null)
/// 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.
/// </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>
/// Gets a collection of users in this guild that the name or nickname starts with the
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ public SocketGuildUser GetUser(ulong id)
return null;
}
/// <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)
{
Expand Down

0 comments on commit a80e5ff

Please sign in to comment.