Files
Bat/src/main/java/cc/fascinated/bat/common/MemberUtils.java
Liam fa10cf2019
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m10s
add spotify feature
2024-06-28 03:01:21 +01:00

41 lines
1.3 KiB
Java

package cc.fascinated.bat.common;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import java.util.Comparator;
/**
* @author Fascinated (fascinated7)
*/
public class MemberUtils {
/**
* Checks if a user has permission to edit another user
*
* @param guild the guild to check
* @param user the user to check
* @return if the user has permission to edit another user
*/
public static boolean hasPermissionToEdit(BatGuild guild, BatUser user) {
Member botUser = guild.getDiscordGuild().getSelfMember();
Member member = guild.getDiscordGuild().getMemberById(user.getId());
if (member == null) {
return false;
}
return botUser.canInteract(member) && getHighestRole(botUser).getPosition() > getHighestRole(member).getPosition();
}
/**
* Gets the highest role of a member
*
* @param member the member to get the highest role of
* @return the highest role of the member
*/
public static Role getHighestRole(Member member) {
return member.getRoles().stream().max(Comparator.comparingInt(Role::getPosition)).orElse(null);
}
}