Skip to content

Commit

Permalink
GH-471 Fix jda number suggestions (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi authored Nov 2, 2024
1 parent d171f28 commit 5d56811
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.Nullable;

class JDAPlatform extends AbstractPlatform<User, LiteJDASettings> {

Expand Down Expand Up @@ -137,11 +138,13 @@ public void onCommandAutoCompleteInteraction(CommandAutoCompleteInteractionEvent
List<Command.Choice> choiceList = result.getSuggestions().stream()
.filter(suggestion -> !suggestion.multilevel().isEmpty())
.map(suggestion -> choice(event.getFocusedOption().getType(), suggestion))
.filter(Objects::nonNull)
.collect(Collectors.toList());

event.replyChoices(choiceList).queue();
}

@Nullable
private Command.Choice choice(OptionType optionType, Suggestion suggestion) {
String multilevel = suggestion.multilevel();

Expand All @@ -154,7 +157,9 @@ private Command.Choice choice(OptionType optionType, Suggestion suggestion) {
return new Command.Choice(multilevel, Double.parseDouble(multilevel));
}
}
catch (NumberFormatException ignored) {}
catch (NumberFormatException ignored) {
return null;
}

return new Command.Choice(multilevel, multilevel);
}
Expand Down

0 comments on commit 5d56811

Please sign in to comment.