Skip to content

Commit

Permalink
🐛 Fixed some conversion problem in the cooldown checker
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Apr 26, 2024
1 parent cfb97ff commit f0c2fe5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public SlashCommandResponse check(@NotNull SimpleCommand command, @NotNull Slash
if (bypassedUsers.contains(user.getId()))
return provider.success();

if (context.getMember() != null && bypassedRoles.stream().anyMatch(role -> context.getMember().getRoles().stream().anyMatch(r -> r.getId().equals(role))))
if (!bypassedRoles.isEmpty() && context.getMember() != null && bypassedRoles.stream().anyMatch(role -> context.getMember().getRoles().stream().anyMatch(r -> r.getId().equals(role))))
return provider.success();

if (context.getMember() != null && bypassedPermissions.stream().anyMatch(permission -> context.getMember().hasPermission(permission)))
if (!bypassedPermissions.isEmpty() && context.getMember() != null && bypassedPermissions.stream().anyMatch(permission -> context.getMember().hasPermission(permission)))
return provider.success();

final long lastExecution = cooldownMap.getOrDefault(user, 0L);
if (lastExecution + cooldown > now) {
final long remaining = (lastExecution + cooldown - now) / 1000;
if (lastExecution + (cooldown * 1000L) > now) {
final long remaining = (lastExecution + (cooldown * 1000L) - now) / 1000;
return provider.error("You are on cooldown! Please wait " + remaining + " seconds before using this command again.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.greazi.discordbotfoundation.tests;

import com.greazi.discordbotfoundation.command.SimpleCommand;
import com.greazi.discordbotfoundation.command.checkers.CooldownChecker;
import com.greazi.discordbotfoundation.command.checkers.RolesChecker;
import com.greazi.discordbotfoundation.command.checkers.response.DefaultCommandProvider;
import net.dv8tion.jda.api.entities.User;
Expand All @@ -19,7 +20,8 @@ public ReplyCommand() {
addOption(new OptionData(OptionType.STRING, "message", "The message to reply with.").setRequired(true));
addOption(new OptionData(OptionType.USER, "user", "The user to reply to."));

addChecker(RolesChecker.createAllowed(List.of("938425015274180628")));
addChecker(CooldownChecker.create(15)
.bypassRole("938425015274180628"));

setMainGuildOnly(true);
}
Expand Down

0 comments on commit f0c2fe5

Please sign in to comment.