Compare commits

...

18 Commits

Author SHA1 Message Date
ad19ed6ada
add First prototype of Discord4J wrapper
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 21s
Test / Gradle-Test (push) Successful in 14s
2025-02-17 20:13:31 +01:00
ca822909e3
fix: consistency 2025-02-17 19:55:03 +01:00
caeaec1926
add: fromValue method to SlashCommandOptionType 2025-02-17 19:45:18 +01:00
f4dbdc302d
fix: improve consistency 2025-02-17 19:44:52 +01:00
fd87431d51
Merge remote-tracking branch 'origin/dev' into wrapper/d4j 2025-02-17 13:06:27 +01:00
3b65784770 Merge pull request 'Add Choices and Autocomplete' (#8) from feat/choices into dev
All checks were successful
github-mirror / push-github (push) Successful in 30s
Build / Gradle-Build (push) Successful in 14s
Publish / Gradle-Publish (push) Successful in 10s
Test / Gradle-Test (push) Successful in 14s
Reviewed-on: #8
Double choices missing because PR will not get merged since Javacord seized development
2025-02-17 10:14:37 +00:00
1146fa1cc6
Merge branch 'dev' into feat/choices
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 34s
Test / Gradle-Test (push) Successful in 41s
2024-12-20 19:30:35 +01:00
43c5946227
Merge branch 'dev' into feat/choices
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 32s
Test / Gradle-Test (push) Successful in 40s
2024-12-20 17:04:13 +01:00
c5a7f3665e
Merge branch 'dev' into feat/choices
All checks were successful
github-mirror / push-github (push) Successful in 5s
Build / Gradle-Build (push) Successful in 32s
Test / Gradle-Test (push) Successful in 40s
2024-12-20 14:56:35 +01:00
aaf4f3297a
add autocomplete option toggle, add double value for non javacord wrappers, rename OptionChoices to match with discords naming and general cleanup
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 39s
2024-12-16 13:03:11 +01:00
445190db89
added Tests for choices 2024-12-16 12:49:51 +01:00
9d3a6b8b85
add Autocomplete Test
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 33s
Test / Gradle-Test (push) Successful in 39s
2024-12-15 23:15:37 +01:00
1cb6cd0e05
clean up code and switch to request instead of getting from cache 2024-12-15 23:15:29 +01:00
a5e1230fc6
fix issues with ExecutableSlashCommandDefinition equals check 2024-12-15 23:13:57 +01:00
432db43bf5
add remaining parts of AutocompleteInteraction
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 33s
Test / Gradle-Test (push) Successful in 40s
2024-12-15 15:09:09 +01:00
7a2c15d877
create seperate class for ContextObjectProviders and renamed some context parameters from parameter to context.
First parts of AutocompleteInteraction added
2024-12-15 15:08:34 +01:00
f32c7045a1
remove unnecessary getClass call fixing test
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 36s
Test / Gradle-Test (push) Successful in 40s
2024-12-14 12:32:03 +01:00
69b27e4554
add prototype choices implementation
Some checks failed
github-mirror / push-github (push) Successful in 5s
Build / Gradle-Build (push) Successful in 50s
Test / Gradle-Test (push) Failing after 41s
2024-12-13 10:50:30 +01:00
26 changed files with 991 additions and 93 deletions

View File

@ -5,10 +5,12 @@
junit-jupiter = "5.10.2"
log4j = "2.24.1"
javacord = "3.8.0"
discord4j = "3.2.7"
geantyref = "2.0.0"
[libraries]
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
log4j = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j"}
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}

View File

@ -0,0 +1,12 @@
package net.tomatentum.marinara.interaction.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoComplete {
}

View File

@ -0,0 +1,5 @@
package net.tomatentum.marinara.interaction.commands;
public interface ChoiceValueProvider<T> {
T getChoiceValue();
}

View File

@ -0,0 +1,78 @@
package net.tomatentum.marinara.interaction.commands;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import io.leangen.geantyref.AnnotationFormatException;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeFactory;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
public record EnumChoices(Class<? extends Enum<?>> enumClass, ChoiceType type, SlashCommandOptionChoice[] choices) {
private static Method method;
static {
try {
method = ChoiceValueProvider.class.getMethod("getChoiceValue");
} catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
public static EnumChoices of(Class<? extends Enum<?>> enumClass) {
if (!ChoiceValueProvider.class.isAssignableFrom(enumClass))
throw new IllegalArgumentException("Provided class needs to implement the ChoiceValueProvider interface.");
ChoiceType type = parseChoiceType(enumClass);
SlashCommandOptionChoice[] choices = parseChoices(enumClass, type);
return new EnumChoices(enumClass, type, choices);
}
private static ChoiceType parseChoiceType(Class<? extends Enum<?>> enumClass) {
ParameterizedType type = (ParameterizedType) GenericTypeReflector.getExactSuperType(enumClass, ChoiceValueProvider.class);
Type typeParam = type.getActualTypeArguments()[0];
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;
throw new IllegalArgumentException("ChoiceValueProvider need either a String, Number or Decimal type parameter.");
}
private static SlashCommandOptionChoice[] parseChoices(Class<? extends Enum<?>> enumClass, ChoiceType type) {
Enum<? extends Enum<?>>[] constants = enumClass.getEnumConstants();
List<SlashCommandOptionChoice> choices = new ArrayList<>();
for (Enum<? extends Enum<?>> enumInstance : constants) {
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)));
} catch (IllegalAccessException | InvocationTargetException | AnnotationFormatException e) {
e.printStackTrace();
return null;
}
}
return choices.toArray(SlashCommandOptionChoice[]::new);
}
public static enum ChoiceType {
String,
INTEGER,
DOUBLE
}
}

View File

@ -2,8 +2,10 @@ package net.tomatentum.marinara.interaction.commands;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
public record ExecutableSlashCommandDefinition(
SlashCommand applicationCommand,
@ -11,6 +13,13 @@ public record ExecutableSlashCommandDefinition(
SubCommandGroup subCommandGroup,
SlashCommandOption[] options) {
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;
}
@Override
public final boolean equals(Object o) {
if (!(o instanceof ExecutableSlashCommandDefinition))

View File

@ -14,4 +14,11 @@ 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;
public static enum PlaceHolderEnum {
}
}

View File

@ -0,0 +1,8 @@
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 "";
}

View File

@ -1,16 +1,35 @@
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;
}
public static SlashCommandOptionType fromValue(int value) {
for (SlashCommandOptionType type : values()) {
if (type.getValue() == value) {
return type;
}
}
return UNKNOWN;
}
}

View File

@ -0,0 +1,51 @@
package net.tomatentum.marinara.interaction.methods;
import java.lang.reflect.Method;
import net.tomatentum.marinara.Marinara;
import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.parser.AnnotationParser;
import net.tomatentum.marinara.parser.SlashCommandParser;
public class AutoCompleteInteractionMethod extends InteractionMethod {
private ExecutableSlashCommandDefinition commandDefinition;
public AutoCompleteInteractionMethod(Method method,
InteractionHandler handler,
Marinara marinara
) {
super(method, handler, marinara);
}
@Override
public AnnotationParser[] getParsers() {
return new AnnotationParser[] {
new SlashCommandParser(method, (x) -> { this.commandDefinition = x; } )
};
}
@Override
public Object getParameter(Object context, int index) {
Class<?> type = getMethod().getParameterTypes()[index+1];
Object autocompleteOptionValue = marinara.getWrapper().getContextObjectProvider().getAutocompleteFocusedOption(context);
if (autocompleteOptionValue != null)
return autocompleteOptionValue;
return marinara.getWrapper().getContextObjectProvider().getComponentContextObject(context, type);
}
@Override
public boolean canRun(Object context) {
ExecutableSlashCommandDefinition other = marinara.getWrapper().getCommandDefinition(context);
return commandDefinition.equals(other);
}
@Override
public InteractionType getType() {
return InteractionType.AUTOCOMPLETE;
}
}

View File

@ -24,9 +24,9 @@ public class ButtonInteractionMethod extends InteractionMethod {
}
@Override
public Object getParameter(Object parameter, int index) {
public Object getParameter(Object context, int index) {
Class<?> type = getMethod().getParameterTypes()[index+1];
return marinara.getWrapper().getComponentContextObject(parameter, type);
return marinara.getWrapper().getContextObjectProvider().getComponentContextObject(context, type);
}
@Override
@ -38,4 +38,5 @@ public class ButtonInteractionMethod extends InteractionMethod {
public InteractionType getType() {
return InteractionType.BUTTON;
}
}

View File

@ -13,6 +13,7 @@ import net.tomatentum.marinara.Marinara;
import net.tomatentum.marinara.checks.AppliedCheck;
import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.annotation.AutoComplete;
import net.tomatentum.marinara.interaction.annotation.Button;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
@ -24,6 +25,8 @@ import net.tomatentum.marinara.util.ReflectionUtil;
public abstract class InteractionMethod {
public static InteractionMethod create(Method method, InteractionHandler handler, Marinara marinara) {
if (method.isAnnotationPresent(AutoComplete.class))
return new AutoCompleteInteractionMethod(method, handler, marinara);
if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class))
return new SlashCommandInteractionMethod(method, handler, marinara);
if (method.isAnnotationPresent(Button.class))
@ -59,7 +62,7 @@ public abstract class InteractionMethod {
public abstract AnnotationParser[] getParsers();
public abstract Object getParameter(Object parameter, int index);
public abstract Object getParameter(Object context, int index);
public abstract boolean canRun(Object context);

View File

@ -26,7 +26,7 @@ public class SlashCommandInteractionMethod extends InteractionMethod {
@Override
public Object getParameter(Object context, int index) {
return marinara.getWrapper().convertCommandOption(context, commandDefinition.options()[index].type(), commandDefinition.options()[index].name());
return marinara.getWrapper().getContextObjectProvider().convertCommandOption(context, commandDefinition.options()[index].name());
}
@Override

View File

@ -0,0 +1,11 @@
package net.tomatentum.marinara.wrapper;
public interface ContextObjectProvider {
public Object convertCommandOption(Object context, String optionName);
public Object getComponentContextObject(Object context, Class<?> type);
public Object getInteractionContextObject(Object context, Class<?> type);
public Object getAutocompleteFocusedOption(Object context);
}

View File

@ -6,7 +6,6 @@ import java.util.function.Consumer;
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
import net.tomatentum.marinara.interaction.InteractionType;
public abstract class LibraryWrapper {
@ -17,7 +16,6 @@ public abstract class LibraryWrapper {
interactionSubscriber = new ArrayList<>();
}
public void handleInteraction(Object context) {
interactionSubscriber.forEach((o) -> o.accept(context));
}
@ -32,9 +30,10 @@ public abstract class LibraryWrapper {
public abstract InteractionType getInteractionType(Object context);
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
public abstract Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName);
public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
public abstract String getButtonId(Object context);
public abstract Object getComponentContextObject(Object context, Class<?> type);
public abstract ContextObjectProvider getContextObjectProvider();
}

View File

@ -13,5 +13,9 @@ plugins {
rootProject.name = "Marinara"
include(":lib")
include(":wrapper-javacord")
include(":wrapper-discord4j")
project(":wrapper-javacord").projectDir = file("wrapper/javacord")
project(":wrapper-discord4j").projectDir = file("wrapper/discord4j")

View File

@ -0,0 +1,41 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.8/userguide/building_java_projects.html in the Gradle documentation.
*/
plugins {
// Apply the java-library plugin for API and implementation separation.
`java-library`
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation(libs.junit.jupiter)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation(libs.log4j)
implementation(libs.discord4j) {
exclude(module="discord4j-voice")
}
implementation(libs.geantyref)
implementation(project(":lib"))
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
}
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

View File

@ -0,0 +1,102 @@
package net.tomatentum.marinara.wrapper.discord4j;
import java.util.List;
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
import discord4j.core.event.domain.interaction.ComponentInteractionEvent;
import discord4j.core.object.command.ApplicationCommandInteractionOption;
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
public class Discord4JContextObjectProvider implements ContextObjectProvider {
@Override
public Object convertCommandOption(Object context, String optionName) {
if (!(context instanceof ChatInputInteractionEvent))
return null;
ChatInputInteractionEvent interactionEvent = (ChatInputInteractionEvent) context;
List<ApplicationCommandInteractionOption> subOptions = Discord4JWrapper.SUB_FILTER.apply(interactionEvent.getOptions());
if (subOptions.isEmpty())
return getOptionValue(interactionEvent.getOption(optionName).get());
ApplicationCommandInteractionOption subCommandOption = interactionEvent.getOptions().getFirst();
subOptions = Discord4JWrapper.SUB_FILTER.apply(subCommandOption.getOptions());
if (!subOptions.isEmpty())
subCommandOption = subOptions.getFirst();
return getOptionValue(interactionEvent.getOption(optionName).get());
}
private Object getOptionValue(ApplicationCommandInteractionOption option) {
if (!option.getValue().isPresent())
return null;
SlashCommandOptionType type = getOptionType(option);
switch (type) {
case ATTACHMENT:
return option.getValue().get().asAttachment();
case BOOLEAN:
return option.getValue().get().asBoolean();
case CHANNEL:
return option.getValue().get().asChannel();
case DOUBLE:
return option.getValue().get().asDouble();
case INTEGER:
return option.getValue().get().asLong();
case MENTIONABLE:
return option.getValue().get().asSnowflake();
case ROLE:
return option.getValue().get().asRole();
case STRING:
return option.getValue().get().asString();
case USER:
return option.getValue().get().asUser();
default:
return null;
}
}
private SlashCommandOptionType getOptionType(ApplicationCommandInteractionOption option) {
return SlashCommandOptionType.fromValue(option.getType().getValue());
}
@Override
public Object getComponentContextObject(Object context, Class<?> type) {
ComponentInteractionEvent componentInteractionEvent = (ComponentInteractionEvent) context;
switch (type.getName()) {
case "discord4j.core.object.entity.Message":
return componentInteractionEvent.getMessage();
default:
return getInteractionContextObject(context, type);
}
}
@Override
public Object getInteractionContextObject(Object context, Class<?> type) {
ComponentInteractionEvent componentInteractionEvent = (ComponentInteractionEvent) context;
switch (type.getName()) {
case "discord4j.core.object.entity.channel.MessageChannel":
return componentInteractionEvent.getInteraction().getChannel().block();
case "discord4j.core.object.entity.Guild":
return componentInteractionEvent.getInteraction().getGuild().block();
case "discord4j.core.object.entity.Member":
return componentInteractionEvent.getInteraction().getMember().orElse(null);
case "discord4j.core.object.entity.User":
return componentInteractionEvent.getInteraction().getUser();
}
return null;
}
@Override
public Object getAutocompleteFocusedOption(Object context) {
ChatInputAutoCompleteEvent interaction = (ChatInputAutoCompleteEvent) context;
return getOptionValue(interaction.getFocusedOption());
}
}

View File

@ -0,0 +1,201 @@
package net.tomatentum.marinara.wrapper.discord4j;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.logging.log4j.Logger;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
import discord4j.core.event.domain.interaction.InteractionCreateEvent;
import discord4j.core.object.command.ApplicationCommandInteractionOption;
import discord4j.core.object.command.ApplicationCommandOption.Type;
import discord4j.discordjson.json.ApplicationCommandOptionChoiceData;
import discord4j.discordjson.json.ApplicationCommandOptionData;
import discord4j.discordjson.json.ApplicationCommandRequest;
import io.leangen.geantyref.AnnotationFormatException;
import io.leangen.geantyref.TypeFactory;
import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
import net.tomatentum.marinara.util.LoggerUtil;
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
import net.tomatentum.marinara.wrapper.LibraryWrapper;
import reactor.core.publisher.Mono;
public class Discord4JWrapper extends LibraryWrapper {
public static final Function<List<ApplicationCommandInteractionOption>, List<ApplicationCommandInteractionOption>> SUB_FILTER = (i) ->
i.stream()
.filter(o -> o.getType().equals(Type.SUB_COMMAND) || o.getType().equals(Type.SUB_COMMAND_GROUP))
.toList();
public static final Function<List<ApplicationCommandInteractionOption>, List<ApplicationCommandInteractionOption>> ARG_FILTER = (i) ->
i.stream()
.filter(o -> !o.getType().equals(Type.SUB_COMMAND) && !o.getType().equals(Type.SUB_COMMAND_GROUP))
.toList();
private GatewayDiscordClient api;
private Discord4JContextObjectProvider contextObjectProvider;
private Logger logger = LoggerUtil.getLogger(getClass());
public Discord4JWrapper(GatewayDiscordClient api) {
this.api = api;
this.contextObjectProvider = new Discord4JContextObjectProvider();
api.on(InteractionCreateEvent.class)
.subscribe(event -> handleInteraction(event));
Mono.just("test").subscribe(logger::debug);
logger.info("Discord4J wrapper loaded!");
}
@Override
public InteractionType getInteractionType(Object context) {
if (ChatInputAutoCompleteEvent.class.isAssignableFrom(context.getClass()))
return InteractionType.AUTOCOMPLETE;
if (ChatInputInteractionEvent.class.isAssignableFrom(context.getClass()))
return InteractionType.COMMAND;
if (ButtonInteractionEvent.class.isAssignableFrom(context.getClass()))
return InteractionType.BUTTON;
return null;
}
@Override
public void registerSlashCommands(SlashCommandDefinition[] defs) {
HashMap<Long, List<ApplicationCommandRequest>> serverCommands = new HashMap<>();
List<ApplicationCommandRequest> globalCommands = new ArrayList<>();
long applicationId = api.getRestClient().getApplicationId().block();
for (SlashCommandDefinition slashCommandDefinition : defs) {
ApplicationCommandRequest request = convertSlashCommand(slashCommandDefinition);
if (slashCommandDefinition.getFullSlashCommand().serverIds().length > 0) {
for (long serverId : slashCommandDefinition.getFullSlashCommand().serverIds()) {
serverCommands.putIfAbsent(serverId, new ArrayList<>());
serverCommands.get(serverId).add(request);
}
}else
globalCommands.add(request);
}
for (long serverId : serverCommands.keySet()) {
api.getRestClient().getApplicationService().bulkOverwriteGuildApplicationCommand(applicationId, serverId, serverCommands.get(serverId));
}
api.getRestClient().getApplicationService().bulkOverwriteGlobalApplicationCommand(applicationId, globalCommands);
}
@Override
public ExecutableSlashCommandDefinition getCommandDefinition(Object context) {
if (!(context instanceof ChatInputInteractionEvent))
return null;
ChatInputInteractionEvent interaction = (ChatInputInteractionEvent) context;
ExecutableSlashCommandDefinition.Builder builder = new ExecutableSlashCommandDefinition.Builder();
List<ApplicationCommandInteractionOption> options = SUB_FILTER.apply(interaction.getOptions());
try {
builder.setApplicationCommand(TypeFactory.annotation(SlashCommand.class, Map.of("name", interaction.getCommandName())));
if (!options.isEmpty()) {
if (!ARG_FILTER.apply(options.getFirst().getOptions()).isEmpty()) {
builder.setSubCommandGroup(TypeFactory.annotation(SubCommandGroup.class, Map.of("name", options.getFirst().getName())));
builder.setSubCommand(TypeFactory.annotation(SubCommand.class, Map.of("name", SUB_FILTER.apply(options.getFirst().getOptions()).getFirst().getName())));
}else
builder.setSubCommand(TypeFactory.annotation(SubCommand.class, Map.of("name", options.getFirst().getName())));
}
} catch (AnnotationFormatException e) {
logger.fatal(e);
}
return builder.build();
}
private ApplicationCommandRequest convertSlashCommand(SlashCommandDefinition def) {
List<ApplicationCommandOptionData> options = new ArrayList<>();
SlashCommand cmd = def.getFullSlashCommand();
if (!def.isRootCommand()) {
Arrays.stream(def.getSubCommands(null)).map(this::convertSubCommandDef).forEach(options::add);
Arrays.stream(def.getSubCommandGroups()).map((x) -> convertSubCommandGroupDef(def, x)).forEach(options::add);
}else {
Arrays.stream(cmd.options()).map(this::convertOptionDef).forEach(options::add);
}
return ApplicationCommandRequest.builder()
.name(cmd.name())
.description(cmd.description())
.options(options)
.build();
}
private ApplicationCommandOptionData convertSubCommandGroupDef(SlashCommandDefinition def, SubCommandGroup subGroup) {
SubCommand[] subCommands = def.getSubCommands(subGroup.name());
List<ApplicationCommandOptionData> convertedSubCommands = Arrays.stream(subCommands).map(this::convertSubCommandDef).toList();
return ApplicationCommandOptionData.builder()
.type(Type.SUB_COMMAND_GROUP.getValue())
.name(subGroup.name())
.description(subGroup.description())
.options(convertedSubCommands)
.build();
}
private ApplicationCommandOptionData convertSubCommandDef(SubCommand sub) {
List<ApplicationCommandOptionData> convertedOptions = Arrays.stream(sub.options()).map(this::convertOptionDef).toList();
return ApplicationCommandOptionData.builder()
.type(Type.SUB_COMMAND_GROUP.getValue())
.name(sub.name())
.description(sub.description())
.options(convertedOptions)
.build();
}
private ApplicationCommandOptionData convertOptionDef(SlashCommandOption option) {
Type type = Enum.valueOf(Type.class, option.type().toString());
return ApplicationCommandOptionData.builder()
.type(type.getValue())
.name(option.name())
.description(option.description())
.required(option.required())
.autocomplete(option.autocomplete())
.choices(convertChoices(option))
.build();
}
private List<ApplicationCommandOptionChoiceData> convertChoices(SlashCommandOption option) {
List<ApplicationCommandOptionChoiceData> convertedChoices = new ArrayList<>();
for (SlashCommandOptionChoice choice : ExecutableSlashCommandDefinition.getActualChoices(option)) {
var builder = ApplicationCommandOptionChoiceData.builder();
builder.name(choice.name());
if (choice.longValue() != Long.MAX_VALUE)
builder.value(choice.longValue());
if (choice.doubleValue() != Double.MAX_VALUE)
builder.value(choice.doubleValue());
if (!choice.stringValue().isEmpty())
builder.value(choice.stringValue());
}
return convertedChoices;
}
@Override
public String getButtonId(Object context) {
ButtonInteractionEvent button = (ButtonInteractionEvent) context;
return button.getCustomId();
}
@Override
public ContextObjectProvider getContextObjectProvider() {
return this.contextObjectProvider;
}
}

View File

@ -0,0 +1,110 @@
package net.tomatentum.marinara.wrapper.javacord;
import org.javacord.api.interaction.AutocompleteInteraction;
import org.javacord.api.interaction.ButtonInteraction;
import org.javacord.api.interaction.SlashCommandInteraction;
import org.javacord.api.interaction.SlashCommandInteractionOption;
import org.javacord.api.interaction.SlashCommandOptionType;
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
public class JavacordContextObjectProvider implements ContextObjectProvider {
@Override
public Object convertCommandOption(Object context, String optionName) {
if (!(context instanceof SlashCommandInteraction))
return null;
SlashCommandInteraction interaction = (SlashCommandInteraction) context;
if (!interaction.getArguments().isEmpty())
return getOptionValue(interaction.getOptionByName(optionName).get());
SlashCommandInteractionOption subCommandOption = interaction.getOptions().getFirst();
if (!subCommandOption.getOptions().isEmpty())
subCommandOption = subCommandOption.getOptions().getFirst();
return getOptionValue(subCommandOption.getOptionByName(optionName).get());
}
private Object getOptionValue(SlashCommandInteractionOption option) {
SlashCommandOptionType type = getOptionType(option);
switch (type) {
case ATTACHMENT:
return option.getAttachmentValue().get();
case BOOLEAN:
return option.getBooleanValue().get();
case CHANNEL:
return option.getChannelValue().get();
case DECIMAL:
return option.getDecimalValue().get();
case LONG:
return option.getLongValue().get();
case MENTIONABLE:
return option.requestMentionableValue().get();
case ROLE:
return option.getRoleValue().get();
case STRING:
return option.getStringValue().get();
case USER:
return option.requestUserValue().get();
default:
return null;
}
}
private SlashCommandOptionType getOptionType(SlashCommandInteractionOption option) {
if (option.getAttachmentValue().isPresent())
return SlashCommandOptionType.ATTACHMENT;
if (option.getBooleanValue().isPresent())
return SlashCommandOptionType.BOOLEAN;
if (option.getChannelValue().isPresent())
return SlashCommandOptionType.CHANNEL;
if (option.getDecimalValue().isPresent())
return SlashCommandOptionType.DECIMAL;
if (option.getLongValue().isPresent())
return SlashCommandOptionType.LONG;
if (option.requestMentionableValue().isPresent())
return SlashCommandOptionType.MENTIONABLE;
if (option.getRoleValue().isPresent())
return SlashCommandOptionType.ROLE;
if (option.getStringValue().isPresent())
return SlashCommandOptionType.STRING;
if (option.requestUserValue().isPresent())
return SlashCommandOptionType.USER;
return SlashCommandOptionType.UNKNOWN;
}
@Override
public Object getComponentContextObject(Object context, Class<?> type) {
ButtonInteraction button = (ButtonInteraction) context;
switch (type.getName()) {
case "org.javacord.api.entity.message.Message":
return button.getMessage();
default:
return getInteractionContextObject(context, type);
}
}
@Override
public Object getInteractionContextObject(Object context, Class<?> type) {
ButtonInteraction button = (ButtonInteraction) context;
switch (type.getName()) {
case "org.javacord.api.entity.channel.TextChannel":
return button.getChannel().orElse(null);
case "org.javacord.api.entity.server.Server":
return button.getServer().orElse(null);
case "org.javacord.api.entity.user.User":
return button.getUser();
}
return null;
}
@Override
public Object getAutocompleteFocusedOption(Object context) {
AutocompleteInteraction interaction = (AutocompleteInteraction) context;
return getOptionValue(interaction.getFocusedOption());
}
}

View File

@ -11,10 +11,14 @@ import java.util.Set;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.interaction.ApplicationCommandInteraction;
import org.javacord.api.interaction.AutocompleteInteraction;
import org.javacord.api.interaction.ButtonInteraction;
import org.javacord.api.interaction.SlashCommandBuilder;
import org.javacord.api.interaction.SlashCommandInteraction;
import org.javacord.api.interaction.SlashCommandInteractionOption;
import org.javacord.api.interaction.SlashCommandOptionBuilder;
import org.javacord.api.interaction.SlashCommandOptionChoiceBuilder;
import org.javacord.api.interaction.SlashCommandOptionType;
import io.leangen.geantyref.AnnotationFormatException;
import io.leangen.geantyref.TypeFactory;
@ -23,31 +27,35 @@ import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefini
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
import net.tomatentum.marinara.util.LoggerUtil;
import net.tomatentum.marinara.wrapper.LibraryWrapper;
public class JavacordWrapper extends LibraryWrapper {
private DiscordApi api;
private JavacordContextObjectProvider contextObjectProvider;
private Logger logger = LoggerUtil.getLogger(getClass());
public JavacordWrapper(DiscordApi api) {
this.api = api;
this.contextObjectProvider = new JavacordContextObjectProvider();
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
logger.info("Javacord wrapper loaded!");
}
@Override
public InteractionType getInteractionType(Object context) {
if (AutocompleteInteraction.class.isAssignableFrom(context.getClass()))
return InteractionType.AUTOCOMPLETE;
if (ApplicationCommandInteraction.class.isAssignableFrom(context.getClass()))
return InteractionType.COMMAND;
if (ButtonInteraction.class.isAssignableFrom(context.getClass()))
return InteractionType.BUTTON;
return null;
}
@ -72,22 +80,6 @@ public class JavacordWrapper extends LibraryWrapper {
api.bulkOverwriteGlobalApplicationCommands(globalCommands);
}
@Override
public Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName) {
if (!(context instanceof SlashCommandInteraction))
return null;
SlashCommandInteraction interaction = (SlashCommandInteraction) context;
if (!interaction.getArguments().isEmpty())
return getOptionValue(interaction.getOptionByName(optionName).get(), type);
SlashCommandInteractionOption subCommandOption = interaction.getOptions().getFirst();
if (!subCommandOption.getOptions().isEmpty())
subCommandOption = subCommandOption.getOptions().getFirst();
return getOptionValue(subCommandOption.getOptionByName(optionName).get(), type);
}
@Override
public ExecutableSlashCommandDefinition getCommandDefinition(Object context) {
if (!(context instanceof SlashCommandInteraction))
@ -127,44 +119,53 @@ public class JavacordWrapper extends LibraryWrapper {
private org.javacord.api.interaction.SlashCommandOption convertSubCommandGroupDef(SlashCommandDefinition def, SubCommandGroup subGroup) {
SubCommand[] subCommands = def.getSubCommands(subGroup.name());
org.javacord.api.interaction.SlashCommandOption[] convertedSubCommands = (org.javacord.api.interaction.SlashCommandOption[]) Arrays.stream(subCommands).map(this::convertSubCommandDef).toArray();
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND_GROUP, subGroup.name(), subGroup.description(), Arrays.asList(convertedSubCommands));
List<org.javacord.api.interaction.SlashCommandOption> convertedSubCommands = Arrays.stream(subCommands).map(this::convertSubCommandDef).toList();
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(
org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND_GROUP,
subGroup.name(),
subGroup.description(),
convertedSubCommands);
}
private org.javacord.api.interaction.SlashCommandOption convertSubCommandDef(SubCommand sub) {
List<org.javacord.api.interaction.SlashCommandOption> convertedOptions = new ArrayList<>();
Arrays.stream(sub.options()).map(this::convertOptionDef).forEach(convertedOptions::add);
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND, sub.name(), sub.description(), convertedOptions);
List<org.javacord.api.interaction.SlashCommandOption> convertedOptions = Arrays.stream(sub.options()).map(this::convertOptionDef).toList();
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(
org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND,
sub.name(),
sub.description(),
convertedOptions);
}
private org.javacord.api.interaction.SlashCommandOption convertOptionDef(SlashCommandOption option) {
org.javacord.api.interaction.SlashCommandOptionType type = Enum.valueOf(org.javacord.api.interaction.SlashCommandOptionType.class, option.type().toString());
return org.javacord.api.interaction.SlashCommandOption.create(type, option.name(), option.description(), option.required());
SlashCommandOptionType type = SlashCommandOptionType.fromValue(option.type().getValue());
SlashCommandOptionBuilder builder = new SlashCommandOptionBuilder();
builder
.setType(type)
.setName(option.name())
.setDescription(option.description())
.setRequired(option.required())
.setAutocompletable(option.autocomplete())
.setChoices(convertChoices(option));
return builder.build();
}
private Object getOptionValue(SlashCommandInteractionOption option, SlashCommandOptionType type) {
switch (type) {
case ATTACHMENT:
return option.getAttachmentValue().get();
case BOOLEAN:
return option.getBooleanValue().get();
case CHANNEL:
return option.getChannelValue().get();
case DECIMAL:
return option.getDecimalValue().get();
case LONG:
return option.getLongValue().get();
case MENTIONABLE:
return option.getMentionableValue().get();
case ROLE:
return option.getRoleValue().get();
case STRING:
return option.getStringValue().get();
case USER:
return option.getUserValue().get();
default:
return null;
private List<org.javacord.api.interaction.SlashCommandOptionChoice> convertChoices(SlashCommandOption option) {
List<org.javacord.api.interaction.SlashCommandOptionChoice> convertedChoices = new ArrayList<>();
for (SlashCommandOptionChoice choice : ExecutableSlashCommandDefinition.getActualChoices(option)) {
SlashCommandOptionChoiceBuilder builder = new SlashCommandOptionChoiceBuilder();
builder.setName(choice.name());
if (choice.longValue() != Long.MAX_VALUE)
builder.setValue(choice.longValue());
/*
not yet available
if (choice.doubleValue() != Double.MAX_VALUE)
builder.setValue(choice.doubleValue());
*/
if (!choice.stringValue().isEmpty())
builder.setValue(choice.stringValue());
}
return convertedChoices;
}
@Override
@ -174,20 +175,8 @@ public class JavacordWrapper extends LibraryWrapper {
}
@Override
public Object getComponentContextObject(Object context, Class<?> type) {
ButtonInteraction button = (ButtonInteraction) context;
switch (type.getName()) {
case "org.javacord.api.entity.channel.TextChannel":
return button.getChannel().orElse(null);
case "org.javacord.api.entity.message.Message":
return button.getMessage();
case "org.javacord.api.entity.server.Server":
return button.getServer().orElse(null);
case "org.javacord.api.entity.user.User":
return button.getUser();
}
return null;
public ContextObjectProvider getContextObjectProvider() {
return contextObjectProvider;
}
}

View File

@ -0,0 +1,23 @@
package net.tomatentum.marinara.test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import net.tomatentum.marinara.Marinara;
import net.tomatentum.marinara.test.mocks.AutocompleteInteractionMock;
import net.tomatentum.marinara.test.mocks.DiscordApiMock;
import net.tomatentum.marinara.wrapper.LibraryWrapper;
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
public class AutoCompleteTest {
@Test
public void testAutocomplete() {
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock()); //null okay as we don't use the discord API in this test.
Marinara marinara = Marinara.load(wrapper);
marinara.getRegistry().addInteractions(new TestAutocomplete());
wrapper.handleInteraction(new AutocompleteInteractionMock());
assertTrue(AutocompleteInteractionMock.didAutocompleteRun);
}
}

View File

@ -0,0 +1,23 @@
package net.tomatentum.marinara.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import org.javacord.api.interaction.AutocompleteInteraction;
import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.annotation.AutoComplete;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
public class TestAutocomplete implements InteractionHandler {
@SlashCommand(name = "test")
@AutoComplete
public void autocomplete(AutocompleteInteraction context, String value) {
System.out.println("Success!");
assertEquals(value, "test");
context.respondWithChoices(Collections.emptyList());
}
}

View File

@ -0,0 +1,20 @@
package net.tomatentum.marinara.test;
import net.tomatentum.marinara.interaction.commands.ChoiceValueProvider;
public enum TestChoiceEnum implements ChoiceValueProvider<String> {
TestValue("testValue"),
FooBar("fooBar"),
Spongebob("spongebob");
private String value;
private TestChoiceEnum(String value) {
this.value = value;
}
@Override
public String getChoiceValue() {
return value;
}
}

View File

@ -20,7 +20,8 @@ public class TestCommand implements InteractionHandler {
@SlashCommandOption(
name = "foo",
description = "foo bar is very fooby",
type = SlashCommandOptionType.STRING
type = SlashCommandOptionType.STRING,
choiceEnum = TestChoiceEnum.class
)
}
)

View File

@ -0,0 +1,179 @@
package net.tomatentum.marinara.test.mocks;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.entity.message.component.HighLevelComponent;
import org.javacord.api.entity.permission.PermissionType;
import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User;
import org.javacord.api.interaction.AutocompleteInteraction;
import org.javacord.api.interaction.DiscordLocale;
import org.javacord.api.interaction.InteractionType;
import org.javacord.api.interaction.SlashCommandInteractionOption;
import org.javacord.api.interaction.SlashCommandOptionChoice;
import org.javacord.api.interaction.callback.InteractionFollowupMessageBuilder;
import org.javacord.api.interaction.callback.InteractionImmediateResponseBuilder;
import org.javacord.api.interaction.callback.InteractionOriginalResponseUpdater;
public class AutocompleteInteractionMock implements AutocompleteInteraction {
public static boolean didAutocompleteRun = false;
@Override
public String getFullCommandName() {
return "test";
}
@Override
public long getCommandId() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getCommandId'");
}
@Override
public String getCommandIdAsString() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getCommandIdAsString'");
}
@Override
public String getCommandName() {
return "test";
}
@Override
public Optional<Long> getRegisteredCommandServerId() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getRegisteredCommandServerId'");
}
@Override
public long getApplicationId() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getApplicationId'");
}
@Override
public InteractionType getType() {
return InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE;
}
@Override
public InteractionImmediateResponseBuilder createImmediateResponder() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'createImmediateResponder'");
}
@Override
public CompletableFuture<InteractionOriginalResponseUpdater> respondLater() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'respondLater'");
}
@Override
public CompletableFuture<InteractionOriginalResponseUpdater> respondLater(boolean ephemeral) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'respondLater'");
}
@Override
public CompletableFuture<Void> respondWithModal(String customId, String title,
List<HighLevelComponent> components) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'respondWithModal'");
}
@Override
public InteractionFollowupMessageBuilder createFollowupMessageBuilder() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'createFollowupMessageBuilder'");
}
@Override
public Optional<Server> getServer() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getServer'");
}
@Override
public Optional<TextChannel> getChannel() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getChannel'");
}
@Override
public User getUser() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getUser'");
}
@Override
public String getToken() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getToken'");
}
@Override
public int getVersion() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getVersion'");
}
@Override
public DiscordLocale getLocale() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getLocale'");
}
@Override
public Optional<DiscordLocale> getServerLocale() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getServerLocale'");
}
@Override
public Optional<EnumSet<PermissionType>> getBotPermissions() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getBotPermissions'");
}
@Override
public DiscordApi getApi() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getApi'");
}
@Override
public long getId() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getId'");
}
@Override
public List<SlashCommandInteractionOption> getOptions() {
return new ArrayList<>();
}
@Override
public List<SlashCommandInteractionOption> getArguments() {
return new ArrayList<>();
}
@Override
public CompletableFuture<Void> respondWithChoices(List<SlashCommandOptionChoice> choices) {
didAutocompleteRun = true;
return CompletableFuture.completedFuture(null);
}
@Override
public SlashCommandInteractionOption getFocusedOption() {
return new SlashCommandInteractionOptionMock();
}
}

View File

@ -41,52 +41,52 @@ public class SlashCommandInteractionOptionMock implements SlashCommandInteractio
@Override
public Optional<Long> getLongValue() {
throw new UnsupportedOperationException("Unimplemented method 'getLongValue'");
return Optional.empty();
}
@Override
public Optional<Boolean> getBooleanValue() {
throw new UnsupportedOperationException("Unimplemented method 'getBooleanValue'");
return Optional.empty();
}
@Override
public Optional<User> getUserValue() {
throw new UnsupportedOperationException("Unimplemented method 'getUserValue'");
return Optional.empty();
}
@Override
public Optional<CompletableFuture<User>> requestUserValue() {
throw new UnsupportedOperationException("Unimplemented method 'requestUserValue'");
return Optional.empty();
}
@Override
public Optional<ServerChannel> getChannelValue() {
throw new UnsupportedOperationException("Unimplemented method 'getChannelValue'");
return Optional.empty();
}
@Override
public Optional<Attachment> getAttachmentValue() {
throw new UnsupportedOperationException("Unimplemented method 'getAttachmentValue'");
return Optional.empty();
}
@Override
public Optional<Role> getRoleValue() {
throw new UnsupportedOperationException("Unimplemented method 'getRoleValue'");
return Optional.empty();
}
@Override
public Optional<Mentionable> getMentionableValue() {
throw new UnsupportedOperationException("Unimplemented method 'getMentionableValue'");
return Optional.empty();
}
@Override
public Optional<Double> getDecimalValue() {
throw new UnsupportedOperationException("Unimplemented method 'getDecimalValue'");
return Optional.empty();
}
@Override
public Optional<CompletableFuture<Mentionable>> requestMentionableValue() {
throw new UnsupportedOperationException("Unimplemented method 'requestMentionableValue'");
return Optional.empty();
}
@Override