Skip to content

Commit 49af85c

Browse files
committed
Replace checkDontHaveRole(...) methods with one common
`LazyRole#checkDontHaveRole(IReplyCallback)`
1 parent 67f6436 commit 49af85c

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/main/java/xyz/srnyx/lazylibrary/config/LazyRole.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package xyz.srnyx.lazylibrary.config;
22

3-
import com.freya02.botcommands.api.application.context.message.GuildMessageEvent;
43
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
54

65
import net.dv8tion.jda.api.entities.Guild;
76
import net.dv8tion.jda.api.entities.Member;
87
import net.dv8tion.jda.api.entities.Role;
8+
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
99

1010
import org.jetbrains.annotations.NotNull;
1111

@@ -144,21 +144,9 @@ public boolean hasRole(long userId) {
144144
*
145145
* @return {@code true} if the user <b>doesn't</b> have the role, {@code false} if they <b>do</b>
146146
*/
147-
public boolean checkDontHaveRole(@NotNull GuildSlashEvent event) {
148-
final boolean hasRole = hasRole(event.getMember());
149-
if (!hasRole) event.replyEmbeds(LazyEmbed.noPermission(getMention()).build(bot)).setEphemeral(true).queue();
150-
return !hasRole;
151-
}
152-
153-
/**
154-
* Checks if the user who ran the {@link GuildMessageEvent} has the role and replies with an error message if not
155-
*
156-
* @param event the {@link GuildSlashEvent} to get the user from and reply to (if needed)
157-
*
158-
* @return {@code true} if the user <b>doesn't</b> have the role, {@code false} if they <b>do</b>
159-
*/
160-
public boolean checkDontHaveRole(@NotNull GuildMessageEvent event) {
161-
final boolean hasRole = hasRole(event.getMember());
147+
public boolean checkDontHaveRole(@NotNull IReplyCallback event) {
148+
final Member member = event.getMember();
149+
final boolean hasRole = member != null ? hasRole(member) : hasRole(event.getUser().getIdLong());
162150
if (!hasRole) event.replyEmbeds(LazyEmbed.noPermission(getMention()).build(bot)).setEphemeral(true).queue();
163151
return !hasRole;
164152
}

0 commit comments

Comments
 (0)