add autocomplete option toggle, add double value for non javacord wrappers, rename OptionChoices to match with discords naming and general cleanup
This commit is contained in:
		| @@ -40,12 +40,13 @@ public record EnumChoices(Class<? extends Enum<?>> enumClass, ChoiceType type, S | ||||
|         if (!(typeParam instanceof Class<?>)) | ||||
|             throw new IllegalArgumentException("ChoiceValueProvider need either a String or Number type parameter."); | ||||
|  | ||||
|         if (Long.class.isAssignableFrom((Class<?>) typeParam)) | ||||
|             return ChoiceType.INTEGER; | ||||
|         if (Double.class.isAssignableFrom((Class<?>) typeParam)) | ||||
|             return ChoiceType.DOUBLE; | ||||
|         if (String.class.isAssignableFrom((Class<?>) typeParam)) | ||||
|             return ChoiceType.String; | ||||
|         else if (Number.class.isAssignableFrom((Class<?>) typeParam)) | ||||
|             return ChoiceType.Number; | ||||
|         else | ||||
|             throw new IllegalArgumentException("ChoiceValueProvider need either a String or Number type parameter."); | ||||
|         throw new IllegalArgumentException("ChoiceValueProvider need either a String, Number or Decimal type parameter."); | ||||
|     } | ||||
|  | ||||
|     private static SlashCommandOptionChoice[] parseChoices(Class<? extends Enum<?>> enumClass, ChoiceType type) { | ||||
| @@ -55,10 +56,12 @@ public record EnumChoices(Class<? extends Enum<?>> enumClass, ChoiceType type, S | ||||
|             Object value; | ||||
|             try { | ||||
|                 value = method.invoke(enumInstance); | ||||
|                 if (type.equals(ChoiceType.INTEGER)) | ||||
|                     choices.add(TypeFactory.annotation(SlashCommandOptionChoice.class, Map.of("name", enumInstance.name(), "longValue", value))); | ||||
|                 if (type.equals(ChoiceType.DOUBLE)) | ||||
|                     choices.add(TypeFactory.annotation(SlashCommandOptionChoice.class, Map.of("name", enumInstance.name(), "doubleValue", value))); | ||||
|                 if (type.equals(ChoiceType.String)) | ||||
|                     choices.add(TypeFactory.annotation(SlashCommandOptionChoice.class, Map.of("name", enumInstance.name(), "stringValue", value))); | ||||
|                 else if (type.equals(ChoiceType.Number)) | ||||
|                     choices.add(TypeFactory.annotation(SlashCommandOptionChoice.class, Map.of("name", enumInstance.name(), "longValue", value))); | ||||
|             } catch (IllegalAccessException | InvocationTargetException | AnnotationFormatException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 return null; | ||||
| @@ -69,6 +72,7 @@ public record EnumChoices(Class<? extends Enum<?>> enumClass, ChoiceType type, S | ||||
|  | ||||
|     public static enum ChoiceType { | ||||
|         String, | ||||
|         Number | ||||
|         INTEGER, | ||||
|         DOUBLE | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -14,6 +14,7 @@ public @interface SlashCommandOption { | ||||
|     public String description() default ""; | ||||
|     public SlashCommandOptionType type() default SlashCommandOptionType.STRING; | ||||
|     public boolean required() default false; | ||||
|     public boolean autocomplete() default false; | ||||
|     public SlashCommandOptionChoice[] choices() default {}; | ||||
|     public Class<? extends Enum<?>> choiceEnum() default PlaceHolderEnum.class; | ||||
|  | ||||
|   | ||||
| @@ -3,5 +3,6 @@ package net.tomatentum.marinara.interaction.commands.annotation; | ||||
| public @interface SlashCommandOptionChoice { | ||||
|     public String name(); | ||||
|     public long longValue() default Long.MAX_VALUE; | ||||
|     public double doubleValue() default Double.MAX_VALUE; | ||||
|     public String stringValue() default ""; | ||||
| } | ||||
|   | ||||
| @@ -1,16 +1,26 @@ | ||||
| package net.tomatentum.marinara.interaction.commands.option; | ||||
|  | ||||
| public enum SlashCommandOptionType { | ||||
|     ATTACHMENT, | ||||
|     BOOLEAN, | ||||
|     CHANNEL, | ||||
|     DECIMAL, | ||||
|     LONG, | ||||
|     MENTIONABLE, | ||||
|     ROLE, | ||||
|     STRING, | ||||
|     SUB_COMMAND, | ||||
|     SUB_COMMAND_GROUP, | ||||
|     UNKNOW, | ||||
|     USER | ||||
|     SUB_COMMAND(1), | ||||
|     SUB_COMMAND_GROUP(2), | ||||
|     STRING(3), | ||||
|     INTEGER(4), | ||||
|     BOOLEAN(5), | ||||
|     USER(6), | ||||
|     CHANNEL(7), | ||||
|     ROLE(8), | ||||
|     MENTIONABLE(9), | ||||
|     DOUBLE(10), | ||||
|     ATTACHMENT(11), | ||||
|     UNKNOWN(-1); | ||||
|  | ||||
|     private final int value; | ||||
|  | ||||
|     private SlashCommandOptionType(int value) { | ||||
|         this.value = value; | ||||
|     } | ||||
|  | ||||
|     public int getValue() { | ||||
|         return value; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user