Skip to content

Commit

Permalink
Add prune overload to disable wait parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Apr 28, 2020
1 parent 17ac665 commit d60596f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
40 changes: 39 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/Guild.java
Expand Up @@ -2608,6 +2608,9 @@ default RestAction<Void> kickVoiceMember(@Nonnull Member member)
* <br>You can use {@link Guild#retrievePrunableMemberCount(int)} to determine how many Members would be pruned if you were to
* call this method.
*
* <p>This might timeout when pruning many members.
* You can use {@code prune(days, false)} to ignore the prune count and avoid a timeout.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
* <ul>
Expand All @@ -2628,7 +2631,42 @@ default RestAction<Void> kickVoiceMember(@Nonnull Member member)
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<Integer> prune(int days);
default AuditableRestAction<Integer> prune(int days)
{
return prune(days, true);
}

/**
* This method will prune (kick) all members who were offline for at least <i>days</i> days.
* <br>The RestAction returned from this method will return the amount of Members that were pruned.
* <br>You can use {@link Guild#retrievePrunableMemberCount(int)} to determine how many Members would be pruned if you were to
* call this method.
*
* <p>This might timeout when pruning many members with {@code wait=true}.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The prune cannot finished due to a permission discrepancy</li>
* </ul>
*
* @param days
* Minimum number of days since a member has been offline to get affected.
* @param wait
* Whether to calculate the number of pruned members and wait for the response (timeout for too many pruned)
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the account doesn't have {@link net.dv8tion.jda.api.Permission#KICK_MEMBERS KICK_MEMBER} Permission.
* @throws IllegalArgumentException
* If the provided days are less than {@code 1} or more than {@code 30}
*
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction} - Type: Integer
* <br>Provides the amount of Members that were pruned from the Guild, if wait is true.
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<Integer> prune(int days, boolean wait);

/**
* Kicks the {@link net.dv8tion.jda.api.entities.Member Member} from the {@link net.dv8tion.jda.api.entities.Guild Guild}.
Expand Down
Expand Up @@ -905,14 +905,16 @@ public AuditableRestAction<Void> modifyNickname(@Nonnull Member member, String n

@Nonnull
@Override
public AuditableRestAction<Integer> prune(int days)
public AuditableRestAction<Integer> prune(int days, boolean wait)
{
checkPermission(Permission.KICK_MEMBERS);

Checks.check(days >= 1 && days <= 30, "Provided %d days must be between 1 and 30.", days);

Route.CompiledRoute route = Route.Guilds.PRUNE_MEMBERS.compile(getId()).withQueryParams("days", Integer.toString(days));
return new AuditableRestActionImpl<>(getJDA(), route, (response, request) -> response.getObject().getInt("pruned"));
if (!wait)
route = route.withQueryParams("compute_prune_count", "false");
return new AuditableRestActionImpl<>(getJDA(), route, (response, request) -> response.getObject().getInt("pruned", 0));
}

@Nonnull
Expand Down

0 comments on commit d60596f

Please sign in to comment.