package cc.fascinated.bat.common; import cc.fascinated.bat.model.BatGuild; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; /** * @author Fascinated (fascinated7) */ @UtilityClass public class RoleUtils { /** * Checks if a member has permission to give the role to another member * * @param guild the guild to check * @param member the member to check * @param role the role to check * @return if the member has permission to give the role */ public static boolean hasPermissionToGiveRole(BatGuild guild, Member member, Role role) { return member.getRoles().stream().anyMatch(r -> r.getPosition() > role.getPosition()); } /** * Gets the formatted permissions of a role * * @param role the role to get the formatted permissions of * @return the formatted permissions */ public String getFormattedPermissions(Role role) { StringBuilder formattedPermissions = new StringBuilder(); for (Permission permission : role.getPermissions()) { formattedPermissions.append("`").append(permission.getName()).append("`, "); } return formattedPermissions.substring(0, formattedPermissions.length() - 2); } }