Skip to content

Commit

Permalink
Implemented include_roles for guilds/id/prune get&post
Browse files Browse the repository at this point in the history
  • Loading branch information
RheaAyase committed Jun 26, 2020
1 parent c42bfa6 commit 8b41dcc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 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 @@ -704,12 +704,13 @@ public interface IGuild : IDeletable, ISnowflakeEntity
/// </remarks>
/// <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="includeRoleIds">An array of role IDs to include in the prune.</param>
/// <param name="options">The options to be used when sending the request.</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, ulong[] includeRoleIds = null, RequestOptions options = 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 @@ -855,10 +855,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 @@ -376,9 +376,9 @@ public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync
);
}
public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client,
int days, bool simulate, RequestOptions options)
int days, bool simulate, ulong[] includeRoleIds, RequestOptions options)
{
var args = new GuildPruneParams(days);
var args = new GuildPruneParams(days, includeRoleIds);
GetGuildPruneCountResponse model;
if (simulate)
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false);
Expand Down Expand Up @@ -451,7 +451,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 @@ -466,7 +466,7 @@ public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordC
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 @@ -484,7 +484,7 @@ public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordC
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);
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
Original file line number Diff line number Diff line change
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, ulong[] includeRoleIds = null, RequestOptions options = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, includeRoleIds, options);

/// <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, ulong[] includeRoleIds = null, RequestOptions options = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, includeRoleIds, options);

internal SocketGuildUser AddOrUpdateUser(UserModel model)
{
Expand Down

0 comments on commit 8b41dcc

Please sign in to comment.