diff --git a/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java b/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java index 24c5699..72f16de 100644 --- a/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java +++ b/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java @@ -22,7 +22,7 @@ public class PlayCommand extends YoshiCommand { private static final Map cooldownChecker = new HashMap<>(); - private static final int SECOND_DELAY = 10; + private static final int SECOND_DELAY = 5; public PlayCommand(YoshiCommandContext context) { @@ -113,17 +113,9 @@ public class PlayCommand extends YoshiCommand { } private String getBestMatch(String word, List choices) { - double bestScore = 1.0; - String bestMatching = null; - for (String file : choices) { - double score = (new JaccardDistance()).apply(word, file); - if (score < bestScore) { - bestScore = score; - bestMatching = file; - } - } - - return bestMatching; + Optional match = choices.parallelStream().filter(word::equals).findAny(); + return match.orElse(choices.parallelStream().max( + Comparator.comparingDouble(file -> new JaccardDistance().apply(word, file))).orElse(null)); } private List getAllFiles() {