Skip to content

Commit

Permalink
GH-425 Fix @OptionalArg annotation for the jda platform. (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi authored Sep 8, 2024
1 parent 0990398 commit 7d2d3fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public Optional<ParseResult<T>> defaultValue() {
return Optional.empty();
}

@Override
public boolean hasDefaultValue() {
return nullable;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private <SENDER> CommandExecutor<SENDER> translateExecutor(CommandRoute<SENDER>
for (Argument<?> argument : executor.getArguments()) {
String argumentName = argument.getName();
String description = this.getDescription(argument);
boolean isRequired = !wrapperRegistry.getWrappedExpectedFactory(argument.getWrapperFormat()).canCreateEmpty();
boolean isRequired = isRequired(argument);

Class<?> parsedType = argument.getWrapperFormat().getParsedType();
if (jdaSupportedTypes.containsKey(parsedType)) {
Expand All @@ -195,6 +195,14 @@ private <SENDER> CommandExecutor<SENDER> translateExecutor(CommandRoute<SENDER>
return executor;
}

private boolean isRequired(Argument<?> argument) {
if (argument.hasDefaultValue()) {
return false;
}

return !wrapperRegistry.getWrappedExpectedFactory(argument.getWrapperFormat()).canCreateEmpty();
}

private interface TranslateExecutorConsumer {
void translate(OptionType optionType, JDATypeMapper<?> mapper, String argName, String description, boolean isRequired, boolean autocomplete);
}
Expand Down

0 comments on commit 7d2d3fd

Please sign in to comment.