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); } }