From 2a1957229f65362c1b00d062280272b43968d6bf Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 6 Aug 2021 13:58:22 -0400 Subject: [PATCH] Add InteractionMember#hasRole convince methods --- .../v2/services/discord/InteractionMember.java | 14 ++++++++++++++ .../interactions/InteractionMemberImpl.java | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/api/v2/services/discord/InteractionMember.java b/EssentialsDiscord/src/main/java/net/essentialsx/api/v2/services/discord/InteractionMember.java index 453979215..c6ee1f9bc 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/api/v2/services/discord/InteractionMember.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/api/v2/services/discord/InteractionMember.java @@ -64,6 +64,20 @@ public interface InteractionMember { */ boolean hasRoles(List 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. diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionMemberImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionMemberImpl.java index 7982a006a..9abfb994c 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionMemberImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionMemberImpl.java @@ -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; }