Compare commits
8 Commits
4c5e28b679
...
dev
Author | SHA1 | Date | |
---|---|---|---|
a3c5eb62ac | |||
996f854ff7
|
|||
d2eec8b07c
|
|||
caa2ee7089
|
|||
2e5979e6e4 | |||
ab1eb74e85
|
|||
a5737b9eaa
|
|||
faca21724c
|
@@ -6,6 +6,7 @@ import java.util.Set;
|
||||
|
||||
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.PlaceHolderEnum;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
|
||||
@@ -18,10 +19,11 @@ import net.tomatentum.marinara.util.LoggerUtil;
|
||||
public class SlashCommandDefinition {
|
||||
|
||||
public static SlashCommandOptionChoice[] getActualChoices(SlashCommandOption option) {
|
||||
SlashCommandOptionChoice[] choices = option.choices();
|
||||
if (choices.length <= 0 && !option.choiceEnum().equals(PlaceHolderEnum.class))
|
||||
choices = EnumChoices.of(option.choiceEnum()).choices();
|
||||
return choices;
|
||||
CommandChoices choices = option.choices();
|
||||
SlashCommandOptionChoice[] actualChoices = choices.value();
|
||||
if (choices.value().length <= 0 && !choices.cenum().equals(PlaceHolderEnum.class))
|
||||
actualChoices = EnumChoices.of(choices.cenum()).choices();
|
||||
return actualChoices;
|
||||
}
|
||||
|
||||
private Set<InteractionIdentifier> entries;
|
||||
|
@@ -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;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package net.tomatentum.marinara.interaction.commands.annotation;
|
||||
|
||||
public @interface Range {
|
||||
public double min() default Double.MIN_VALUE;
|
||||
public double max() default Double.MAX_VALUE;
|
||||
}
|
@@ -15,8 +15,8 @@ public @interface SlashCommandOption {
|
||||
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;
|
||||
public Range range() default @Range;
|
||||
public CommandChoices choices() default @CommandChoices;
|
||||
|
||||
public static enum PlaceHolderEnum {
|
||||
|
||||
|
@@ -59,7 +59,7 @@ public class SlashCommandParser implements AnnotationParser {
|
||||
.build(isAutoComplete);
|
||||
}
|
||||
|
||||
logger.trace("Parsed using SlashCommandParser for method {} with the result:\n{}", ReflectionUtil.getFullMethodName(method), lastIdentifier.toString());
|
||||
logger.trace("Parsed using SlashCommandParser for method {} with the result: {}", ReflectionUtil.getFullMethodName(method), lastIdentifier.toString());
|
||||
consumer.accept((SlashCommandIdentifier) lastIdentifier);
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,12 @@ package net.tomatentum.marinara.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.helpers.NOPLoggerFactory;
|
||||
|
||||
public class LoggerUtil {
|
||||
public static Logger getLogger(String name) {
|
||||
if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory)
|
||||
return new SimpleLogger(name);
|
||||
return LoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
|
@@ -102,6 +102,6 @@ public final class ReflectionUtil {
|
||||
}
|
||||
|
||||
public static String getFullMethodName(Method method) {
|
||||
return method.getClass().getName() + "." + method.getName();
|
||||
return method.getDeclaringClass().getName() + "." + method.getName();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,55 @@
|
||||
package net.tomatentum.marinara.util;
|
||||
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.event.Level;
|
||||
import org.slf4j.helpers.LegacyAbstractLogger;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
public class SimpleLogger extends LegacyAbstractLogger {
|
||||
|
||||
private String name;
|
||||
|
||||
public SimpleLogger(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFullyQualifiedCallerName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleNormalizedLoggingCall(Level level, Marker marker, String messagePattern, Object[] arguments,
|
||||
Throwable throwable) {
|
||||
String formatted = MessageFormatter.basicArrayFormat(messagePattern, arguments);
|
||||
System.out.println("[%s] %s => %s".formatted(level, this.name, formatted));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -56,6 +56,10 @@ public class Discord4JConverterSpec implements CommandConverter.Spec<Application
|
||||
.description(option.description())
|
||||
.required(option.required())
|
||||
.autocomplete(option.autocomplete())
|
||||
.minLength(Double.valueOf(option.range().min()).intValue())
|
||||
.minValue(option.range().min())
|
||||
.maxLength(Double.valueOf(option.range().max()).intValue())
|
||||
.maxValue(option.range().max())
|
||||
.choices(choices)
|
||||
.build();
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
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.SlashCommandOption;
|
||||
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
|
||||
@@ -20,7 +21,7 @@ public class TestCommand implements InteractionHandler {
|
||||
name = "foo",
|
||||
description = "foo bar is very fooby",
|
||||
type = SlashCommandOptionType.STRING,
|
||||
choiceEnum = TestChoiceEnum.class
|
||||
choices = @CommandChoices(cenum = TestChoiceEnum.class)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@@ -51,6 +51,10 @@ public class JavacordConverterSpec implements CommandConverter.Spec<SlashCommand
|
||||
.setDescription(option.description())
|
||||
.setRequired(option.required())
|
||||
.setAutocompletable(option.autocomplete())
|
||||
.setMinLength(Double.valueOf(option.range().min()).longValue())
|
||||
.setDecimalMinValue(option.range().min())
|
||||
.setMaxLength(Double.valueOf(option.range().max()).longValue())
|
||||
.setDecimalMaxValue(option.range().max())
|
||||
.setChoices(choices)
|
||||
.build();
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.javacord.api.interaction.SlashCommandInteraction;
|
||||
|
||||
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.SlashCommandOption;
|
||||
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
|
||||
@@ -21,7 +22,7 @@ public class TestCommand implements InteractionHandler {
|
||||
name = "foo",
|
||||
description = "foo bar is very fooby",
|
||||
type = SlashCommandOptionType.STRING,
|
||||
choiceEnum = TestChoiceEnum.class
|
||||
choices = @CommandChoices(cenum = TestChoiceEnum.class)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user