Skip to content

Commit

Permalink
Add position check to timeouts (#2540)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Sep 17, 2023
1 parent 070a83d commit d3eda90
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
Expand Up @@ -1503,9 +1503,7 @@ public AuditableRestAction<Void> kick(@Nonnull UserSnowflake user)
Checks.notNull(user, "User");
checkPermission(Permission.KICK_MEMBERS);
checkOwner(user.getIdLong(), "kick");
Member member = resolveMember(user);
if (member != null) // If user is in guild. Check if we are able to ban.
checkPosition(member);
checkPosition(user);

Route.CompiledRoute route = Route.Guilds.KICK_MEMBER.compile(getId(), user.getId());
return new AuditableRestActionImpl<>(getJDA(), route);
Expand All @@ -1521,10 +1519,7 @@ public AuditableRestAction<Void> ban(@Nonnull UserSnowflake user, int duration,
Checks.check(unit.toDays(duration) <= 7, "Deletion timeframe must not be larger than 7 days");
checkPermission(Permission.BAN_MEMBERS);
checkOwner(user.getIdLong(), "ban");

Member member = resolveMember(user);
if (member != null) // If user is in guild. Check if we are able to ban.
checkPosition(member);
checkPosition(user);

Route.CompiledRoute route = Route.Guilds.BAN.compile(getId(), user.getId());
DataObject params = DataObject.empty();
Expand Down Expand Up @@ -1557,6 +1552,7 @@ public AuditableRestAction<Void> timeoutUntil(@Nonnull UserSnowflake user, @Nonn
Checks.check(date.isBefore(OffsetDateTime.now().plusDays(Member.MAX_TIME_OUT_LENGTH)), "Cannot put a member in time out for more than 28 days. Provided: %s", date);
checkPermission(Permission.MODERATE_MEMBERS);
checkOwner(user.getIdLong(), "time out");
checkPosition(user);

return timeoutUntilById0(user.getId(), date);
}
Expand Down Expand Up @@ -1961,8 +1957,9 @@ protected void checkPermission(Permission perm)
throw new InsufficientPermissionException(this, perm);
}

protected void checkPosition(Member member)
protected void checkPosition(UserSnowflake user)
{
Member member = resolveMember(user);
if(!getSelfMember().canInteract(member))
throw new HierarchyException("Can't modify a member with higher or equal highest role than yourself!");
}
Expand Down

0 comments on commit d3eda90

Please sign in to comment.