Compare commits

8 Commits

Author SHA1 Message Date
a3c5eb62ac Merge pull request 'add option ranges' (#20) from feat/option-ranges into dev
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 32s
Publish / Gradle-Publish (push) Successful in 43s
Test / Gradle-Test (push) Successful in 47s
Reviewed-on: #20
2025-03-22 18:42:28 +00:00
996f854ff7 feat(command): add wrapper implementations of option ranges
All checks were successful
github-mirror / push-github (push) Successful in 1m40s
Build / Gradle-Build (push) Successful in 33s
Test / Gradle-Test (push) Successful in 47s
2025-03-22 12:33:21 +01:00
d2eec8b07c feat(command): add option ranges to options 2025-03-22 12:31:25 +01:00
caa2ee7089 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
2025-03-18 09:33:53 +01:00
2e5979e6e4 Merge pull request 'migrate to slf4j' (#18) from migrate/slf4j into dev
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 1m45s
Publish / Gradle-Publish (push) Successful in 1m32s
Test / Gradle-Test (push) Successful in 1m38s
Reviewed-on: #18
2025-03-17 19:34:26 +00:00
ab1eb74e85 fix(logging) implement getQualifiedCallerName
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 35s
Test / Gradle-Test (push) Successful in 48s
2025-03-17 14:36:43 +01:00
a5737b9eaa feat(logging): add Fallback logging
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 31s
Test / Gradle-Test (push) Successful in 47s
2025-03-17 14:13:21 +01:00
faca21724c fix(logging): fix wrong getClass method. 2025-03-17 14:13:00 +01:00
12 changed files with 94 additions and 10 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

@@ -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;
}

View File

@@ -15,8 +15,8 @@ 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 Range range() default @Range;
public Class<? extends Enum<?>> choiceEnum() default PlaceHolderEnum.class; public CommandChoices choices() default @CommandChoices;
public static enum PlaceHolderEnum { public static enum PlaceHolderEnum {

View File

@@ -59,7 +59,7 @@ public class SlashCommandParser implements AnnotationParser {
.build(isAutoComplete); .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); consumer.accept((SlashCommandIdentifier) lastIdentifier);
} }

View File

@@ -2,9 +2,12 @@ package net.tomatentum.marinara.util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.helpers.NOPLoggerFactory;
public class LoggerUtil { public class LoggerUtil {
public static Logger getLogger(String name) { public static Logger getLogger(String name) {
if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory)
return new SimpleLogger(name);
return LoggerFactory.getLogger(name); return LoggerFactory.getLogger(name);
} }

View File

@@ -102,6 +102,6 @@ public final class ReflectionUtil {
} }
public static String getFullMethodName(Method method) { public static String getFullMethodName(Method method) {
return method.getClass().getName() + "." + method.getName(); return method.getDeclaringClass().getName() + "." + method.getName();
} }
} }

View File

@@ -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));
}
}

View File

@@ -56,6 +56,10 @@ public class Discord4JConverterSpec implements CommandConverter.Spec<Application
.description(option.description()) .description(option.description())
.required(option.required()) .required(option.required())
.autocomplete(option.autocomplete()) .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) .choices(choices)
.build(); .build();
} }

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

@@ -51,6 +51,10 @@ public class JavacordConverterSpec implements CommandConverter.Spec<SlashCommand
.setDescription(option.description()) .setDescription(option.description())
.setRequired(option.required()) .setRequired(option.required())
.setAutocompletable(option.autocomplete()) .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) .setChoices(choices)
.build(); .build();
} }

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)
) )
} }
) )