diff --git a/src/main/java/com/the_codeboy/mensabot/commands/mensa/MensaCommand.java b/src/main/java/com/the_codeboy/mensabot/commands/mensa/MensaCommand.java index a675ca9..923812a 100644 --- a/src/main/java/com/the_codeboy/mensabot/commands/mensa/MensaCommand.java +++ b/src/main/java/com/the_codeboy/mensabot/commands/mensa/MensaCommand.java @@ -31,7 +31,9 @@ import java.awt.*; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; public class MensaCommand extends Command { @@ -116,11 +118,14 @@ public void run(CommandEvent event) { private Mensa tryGetMensa(CommandEvent event, String query) { List mensas = OpenMensa.getInstance().searchMensa(query); - if (mensas.size() == 0) { + if (mensas.isEmpty()) { event.replyError("No mensas found matching " + query); } else if (mensas.size() == 1) { return mensas.get(0); } else { + Optional exactMatch = mensas.stream().filter(m -> m.getName().equals(query)).findAny(); + if (exactMatch.isPresent()) + return exactMatch.get(); sendMensas(event, mensas, query); } return null;