Skip to content

Commit

Permalink
Fix some mensas not being selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
the-codeboy committed Jun 17, 2024
1 parent d889c29 commit e351c87
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -116,11 +118,14 @@ public void run(CommandEvent event) {

private Mensa tryGetMensa(CommandEvent event, String query) {
List<Mensa> 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<Mensa> exactMatch = mensas.stream().filter(m -> m.getName().equals(query)).findAny();
if (exactMatch.isPresent())
return exactMatch.get();
sendMensas(event, mensas, query);
}
return null;
Expand Down

0 comments on commit e351c87

Please sign in to comment.