refactor(command): move both choices vars to different annotation
All checks were successful
github-mirror / push-github (push) Successful in 1m36s
Build / Gradle-Build (push) Successful in 31s
Publish / Gradle-Publish (push) Successful in 36s
Test / Gradle-Test (push) Successful in 47s

This commit is contained in:
tueem 2025-03-18 09:33:53 +01:00
parent 2e5979e6e4
commit caa2ee7089
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB
5 changed files with 19 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import net.tomatentum.marinara.interaction.commands.annotation.CommandChoices;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
@ -18,10 +19,11 @@ import net.tomatentum.marinara.util.LoggerUtil;
public class SlashCommandDefinition { public class SlashCommandDefinition {
public static SlashCommandOptionChoice[] getActualChoices(SlashCommandOption option) { public static SlashCommandOptionChoice[] getActualChoices(SlashCommandOption option) {
SlashCommandOptionChoice[] choices = option.choices(); CommandChoices choices = option.choices();
if (choices.length <= 0 && !option.choiceEnum().equals(PlaceHolderEnum.class)) SlashCommandOptionChoice[] actualChoices = choices.value();
choices = EnumChoices.of(option.choiceEnum()).choices(); if (choices.value().length <= 0 && !choices.cenum().equals(PlaceHolderEnum.class))
return choices; actualChoices = EnumChoices.of(choices.cenum()).choices();
return actualChoices;
} }
private Set<InteractionIdentifier> entries; private Set<InteractionIdentifier> entries;

View File

@ -0,0 +1,8 @@
package net.tomatentum.marinara.interaction.commands.annotation;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
public @interface CommandChoices {
public SlashCommandOptionChoice[] value() default {};
public Class<? extends Enum<?>> cenum() default PlaceHolderEnum.class;
}

View File

@ -15,8 +15,7 @@ public @interface SlashCommandOption {
public SlashCommandOptionType type() default SlashCommandOptionType.STRING; public SlashCommandOptionType type() default SlashCommandOptionType.STRING;
public boolean required() default false; public boolean required() default false;
public boolean autocomplete() default false; public boolean autocomplete() default false;
public SlashCommandOptionChoice[] choices() default {}; public CommandChoices choices() default @CommandChoices;
public Class<? extends Enum<?>> choiceEnum() default PlaceHolderEnum.class;
public static enum PlaceHolderEnum { public static enum PlaceHolderEnum {

View File

@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent; import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.commands.annotation.CommandChoices;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType; import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
@ -20,7 +21,7 @@ public class TestCommand implements InteractionHandler {
name = "foo", name = "foo",
description = "foo bar is very fooby", description = "foo bar is very fooby",
type = SlashCommandOptionType.STRING, type = SlashCommandOptionType.STRING,
choiceEnum = TestChoiceEnum.class choices = @CommandChoices(cenum = TestChoiceEnum.class)
) )
} }
) )

View File

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.javacord.api.interaction.SlashCommandInteraction; import org.javacord.api.interaction.SlashCommandInteraction;
import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.commands.annotation.CommandChoices;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType; import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
@ -21,7 +22,7 @@ public class TestCommand implements InteractionHandler {
name = "foo", name = "foo",
description = "foo bar is very fooby", description = "foo bar is very fooby",
type = SlashCommandOptionType.STRING, type = SlashCommandOptionType.STRING,
choiceEnum = TestChoiceEnum.class choices = @CommandChoices(cenum = TestChoiceEnum.class)
) )
} }
) )