Browse Source

[Improved] generalized cooldown

master
Paul Glaß 3 years ago
parent
commit
21524a9109
1 changed files with 8 additions and 5 deletions
  1. +8
    -5
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java

+ 8
- 5
app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java View File

@ -22,6 +22,8 @@ public class PlayCommand extends YoshiCommand {
private static final Map<User, Long> cooldownChecker = new HashMap<>(); private static final Map<User, Long> cooldownChecker = new HashMap<>();
private static final int SECOND_DELAY = 10;
public PlayCommand(YoshiCommandContext context) { public PlayCommand(YoshiCommandContext context) {
super(context); super(context);
@ -32,9 +34,9 @@ public class PlayCommand extends YoshiCommand {
public boolean execute() { public boolean execute() {
if (!super.execute()) return false; if (!super.execute()) return false;
for (User user : cooldownChecker.keySet()){
for (User user : cooldownChecker.keySet()) {
Long timestamp = cooldownChecker.get(user); Long timestamp = cooldownChecker.get(user);
if (timestamp - System.currentTimeMillis() > 60000){
if (timestamp - System.currentTimeMillis() > SECOND_DELAY * 1000) {
cooldownChecker.remove(user); cooldownChecker.remove(user);
} }
} }
@ -95,9 +97,10 @@ public class PlayCommand extends YoshiCommand {
if (YoshiBot.getInstance().jda.getVoiceChannels().parallelStream() if (YoshiBot.getInstance().jda.getVoiceChannels().parallelStream()
.flatMap(vcs -> vcs.getMembers().parallelStream()).map( .flatMap(vcs -> vcs.getMembers().parallelStream()).map(
Member::getUser).noneMatch(user -> user == author)) { Member::getUser).noneMatch(user -> user == author)) {
if (PlayCommand.cooldownChecker.containsKey(author)){
sendErrorMessage("Иди нахуй (geh auf Schwanz), du musst 60s warten, wenn du nicht in einem Channel " +
"bist");
if (PlayCommand.cooldownChecker.containsKey(author)) {
sendErrorMessage(
"Иди нахуй (geh auf Schwanz), du musst " + SECOND_DELAY + "s warten, wenn du nicht in" +
" einem Channel bist");
return false; return false;
} }
PlayCommand.cooldownChecker.put(author, System.currentTimeMillis()); PlayCommand.cooldownChecker.put(author, System.currentTimeMillis());


Loading…
Cancel
Save