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 3aeb2c8..e800d2e 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 @@ -55,7 +55,8 @@ public class PlayCommand extends YoshiCommand { sendErrorMessage("Konnte keinen Audiochannel auswählen."); return false; } - context.getEvent().getMessage().getTextChannel().sendMessage("Spiele '" + requestedFile + "' in '" + vc.getName() + "' ab").queue(); + context.getEvent().getMessage().getTextChannel() + .sendMessage("Spiele '" + requestedFile + "' in '" + vc.getName() + "' ab").queue(); YoshiBot.getInstance().playSound(file, vc); } @@ -63,11 +64,12 @@ public class PlayCommand extends YoshiCommand { } private String getBestMatch(String word, List choices) { - Map hammingDists = + Map hammingDists = choices.parallelStream() .collect(Collectors.toMap(file -> file, - file -> maximalMatchingChars(file, word) * choices.size() + - file.length())); + file -> (double) maximalMatchingChars(file, word) / + Math.max(file.length(), + word.length()))); return hammingDists.keySet().stream() .max((file1, file2) -> (int) Math.signum(hammingDists.get(file1) - hammingDists.get(file2))) .orElse(choices.get(0));