Add InteractionMember#hasRole convince methods

This commit is contained in:
Josh Roy 2021-08-06 13:58:22 -04:00 committed by MD
parent e6af246170
commit 2a1957229f
2 changed files with 31 additions and 0 deletions

View File

@ -64,6 +64,20 @@ public interface InteractionMember {
*/
boolean hasRoles(List<String> roleDefinitions);
/**
* Returns true if the user has the specified {@link InteractionRole role}.
* @param role The role to check for.
* @return true if the member has the specified role.
*/
boolean hasRole(InteractionRole role);
/**
* Returns true if the user has a role by the specified ID.
* @param roleId The role id to check for.
* @return true if the member has a role by the specified ID.
*/
boolean hasRole(String roleId);
/**
* Sends a private message to this member with the given content.
* @param content The message to send.

View File

@ -3,7 +3,9 @@ package net.essentialsx.discord.interactions;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.Role;
import net.essentialsx.api.v2.services.discord.InteractionMember;
import net.essentialsx.api.v2.services.discord.InteractionRole;
import net.essentialsx.discord.util.DiscordUtil;
import java.util.List;
@ -56,6 +58,21 @@ public class InteractionMemberImpl implements InteractionMember {
return DiscordUtil.hasRoles(member, roleDefinitions);
}
@Override
public boolean hasRole(InteractionRole role) {
return hasRole(role.getId());
}
@Override
public boolean hasRole(String roleId) {
for (final Role role : member.getRoles()) {
if (role.getId().equals(roleId)) {
return true;
}
}
return false;
}
public Member getJdaObject() {
return member;
}