Compare commits
No commits in common. "ad19ed6adac5d92aa62a18c5e9d255cfcffe70b6" and "b4af922ac255e6cdc71f804bdcb9768271c70dcc" have entirely different histories.
ad19ed6ada
...
b4af922ac2
@ -5,12 +5,10 @@
|
|||||||
junit-jupiter = "5.10.2"
|
junit-jupiter = "5.10.2"
|
||||||
log4j = "2.24.1"
|
log4j = "2.24.1"
|
||||||
javacord = "3.8.0"
|
javacord = "3.8.0"
|
||||||
discord4j = "3.2.7"
|
|
||||||
geantyref = "2.0.0"
|
geantyref = "2.0.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||||
log4j = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j"}
|
log4j = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j"}
|
||||||
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
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"}
|
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
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 {
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package net.tomatentum.marinara.interaction.commands;
|
|
||||||
|
|
||||||
public interface ChoiceValueProvider<T> {
|
|
||||||
T getChoiceValue();
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,10 +2,8 @@ package net.tomatentum.marinara.interaction.commands;
|
|||||||
|
|
||||||
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.annotation.SlashCommandOptionChoice;
|
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
|
|
||||||
|
|
||||||
public record ExecutableSlashCommandDefinition(
|
public record ExecutableSlashCommandDefinition(
|
||||||
SlashCommand applicationCommand,
|
SlashCommand applicationCommand,
|
||||||
@ -13,13 +11,6 @@ public record ExecutableSlashCommandDefinition(
|
|||||||
SubCommandGroup subCommandGroup,
|
SubCommandGroup subCommandGroup,
|
||||||
SlashCommandOption[] options) {
|
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
|
@Override
|
||||||
public final boolean equals(Object o) {
|
public final boolean equals(Object o) {
|
||||||
if (!(o instanceof ExecutableSlashCommandDefinition))
|
if (!(o instanceof ExecutableSlashCommandDefinition))
|
||||||
|
@ -14,11 +14,4 @@ public @interface SlashCommandOption {
|
|||||||
public String description() default "";
|
public String description() default "";
|
||||||
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 SlashCommandOptionChoice[] choices() default {};
|
|
||||||
public Class<? extends Enum<?>> choiceEnum() default PlaceHolderEnum.class;
|
|
||||||
|
|
||||||
public static enum PlaceHolderEnum {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
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,35 +1,16 @@
|
|||||||
package net.tomatentum.marinara.interaction.commands.option;
|
package net.tomatentum.marinara.interaction.commands.option;
|
||||||
|
|
||||||
public enum SlashCommandOptionType {
|
public enum SlashCommandOptionType {
|
||||||
SUB_COMMAND(1),
|
ATTACHMENT,
|
||||||
SUB_COMMAND_GROUP(2),
|
BOOLEAN,
|
||||||
STRING(3),
|
CHANNEL,
|
||||||
INTEGER(4),
|
DECIMAL,
|
||||||
BOOLEAN(5),
|
LONG,
|
||||||
USER(6),
|
MENTIONABLE,
|
||||||
CHANNEL(7),
|
ROLE,
|
||||||
ROLE(8),
|
STRING,
|
||||||
MENTIONABLE(9),
|
SUB_COMMAND,
|
||||||
DOUBLE(10),
|
SUB_COMMAND_GROUP,
|
||||||
ATTACHMENT(11),
|
UNKNOW,
|
||||||
UNKNOWN(-1);
|
USER
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -24,9 +24,9 @@ public class ButtonInteractionMethod extends InteractionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getParameter(Object context, int index) {
|
public Object getParameter(Object parameter, int index) {
|
||||||
Class<?> type = getMethod().getParameterTypes()[index+1];
|
Class<?> type = getMethod().getParameterTypes()[index+1];
|
||||||
return marinara.getWrapper().getContextObjectProvider().getComponentContextObject(context, type);
|
return marinara.getWrapper().getComponentContextObject(parameter, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,5 +38,4 @@ public class ButtonInteractionMethod extends InteractionMethod {
|
|||||||
public InteractionType getType() {
|
public InteractionType getType() {
|
||||||
return InteractionType.BUTTON;
|
return InteractionType.BUTTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import net.tomatentum.marinara.Marinara;
|
|||||||
import net.tomatentum.marinara.checks.AppliedCheck;
|
import net.tomatentum.marinara.checks.AppliedCheck;
|
||||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||||
import net.tomatentum.marinara.interaction.InteractionType;
|
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.annotation.Button;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
@ -25,8 +24,6 @@ import net.tomatentum.marinara.util.ReflectionUtil;
|
|||||||
public abstract class InteractionMethod {
|
public abstract class InteractionMethod {
|
||||||
|
|
||||||
public static InteractionMethod create(Method method, InteractionHandler handler, Marinara marinara) {
|
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))
|
if (method.isAnnotationPresent(SlashCommand.class) || method.isAnnotationPresent(SubCommand.class))
|
||||||
return new SlashCommandInteractionMethod(method, handler, marinara);
|
return new SlashCommandInteractionMethod(method, handler, marinara);
|
||||||
if (method.isAnnotationPresent(Button.class))
|
if (method.isAnnotationPresent(Button.class))
|
||||||
@ -62,7 +59,7 @@ public abstract class InteractionMethod {
|
|||||||
|
|
||||||
public abstract AnnotationParser[] getParsers();
|
public abstract AnnotationParser[] getParsers();
|
||||||
|
|
||||||
public abstract Object getParameter(Object context, int index);
|
public abstract Object getParameter(Object parameter, int index);
|
||||||
|
|
||||||
public abstract boolean canRun(Object context);
|
public abstract boolean canRun(Object context);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class SlashCommandInteractionMethod extends InteractionMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getParameter(Object context, int index) {
|
public Object getParameter(Object context, int index) {
|
||||||
return marinara.getWrapper().getContextObjectProvider().convertCommandOption(context, commandDefinition.options()[index].name());
|
return marinara.getWrapper().convertCommandOption(context, commandDefinition.options()[index].type(), commandDefinition.options()[index].name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -6,6 +6,7 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
||||||
|
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
|
||||||
import net.tomatentum.marinara.interaction.InteractionType;
|
import net.tomatentum.marinara.interaction.InteractionType;
|
||||||
|
|
||||||
public abstract class LibraryWrapper {
|
public abstract class LibraryWrapper {
|
||||||
@ -16,6 +17,7 @@ public abstract class LibraryWrapper {
|
|||||||
interactionSubscriber = new ArrayList<>();
|
interactionSubscriber = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleInteraction(Object context) {
|
public void handleInteraction(Object context) {
|
||||||
interactionSubscriber.forEach((o) -> o.accept(context));
|
interactionSubscriber.forEach((o) -> o.accept(context));
|
||||||
}
|
}
|
||||||
@ -30,10 +32,9 @@ public abstract class LibraryWrapper {
|
|||||||
public abstract InteractionType getInteractionType(Object context);
|
public abstract InteractionType getInteractionType(Object context);
|
||||||
|
|
||||||
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
||||||
|
public abstract Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName);
|
||||||
public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
|
public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
|
||||||
|
|
||||||
public abstract String getButtonId(Object context);
|
public abstract String getButtonId(Object context);
|
||||||
|
public abstract Object getComponentContextObject(Object context, Class<?> type);
|
||||||
public abstract ContextObjectProvider getContextObjectProvider();
|
|
||||||
|
|
||||||
}
|
}
|
@ -13,9 +13,5 @@ plugins {
|
|||||||
rootProject.name = "Marinara"
|
rootProject.name = "Marinara"
|
||||||
include(":lib")
|
include(":lib")
|
||||||
include(":wrapper-javacord")
|
include(":wrapper-javacord")
|
||||||
include(":wrapper-discord4j")
|
|
||||||
|
|
||||||
|
|
||||||
project(":wrapper-javacord").projectDir = file("wrapper/javacord")
|
project(":wrapper-javacord").projectDir = file("wrapper/javacord")
|
||||||
project(":wrapper-discord4j").projectDir = file("wrapper/discord4j")
|
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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()
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,201 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,14 +11,10 @@ import java.util.Set;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.javacord.api.DiscordApi;
|
import org.javacord.api.DiscordApi;
|
||||||
import org.javacord.api.interaction.ApplicationCommandInteraction;
|
import org.javacord.api.interaction.ApplicationCommandInteraction;
|
||||||
import org.javacord.api.interaction.AutocompleteInteraction;
|
|
||||||
import org.javacord.api.interaction.ButtonInteraction;
|
import org.javacord.api.interaction.ButtonInteraction;
|
||||||
import org.javacord.api.interaction.SlashCommandBuilder;
|
import org.javacord.api.interaction.SlashCommandBuilder;
|
||||||
import org.javacord.api.interaction.SlashCommandInteraction;
|
import org.javacord.api.interaction.SlashCommandInteraction;
|
||||||
import org.javacord.api.interaction.SlashCommandInteractionOption;
|
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.AnnotationFormatException;
|
||||||
import io.leangen.geantyref.TypeFactory;
|
import io.leangen.geantyref.TypeFactory;
|
||||||
@ -27,35 +23,31 @@ import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefini
|
|||||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
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.annotation.SlashCommandOptionChoice;
|
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
|
||||||
import net.tomatentum.marinara.util.LoggerUtil;
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
|
|
||||||
public class JavacordWrapper extends LibraryWrapper {
|
public class JavacordWrapper extends LibraryWrapper {
|
||||||
|
|
||||||
private DiscordApi api;
|
private DiscordApi api;
|
||||||
private JavacordContextObjectProvider contextObjectProvider;
|
|
||||||
|
|
||||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public JavacordWrapper(DiscordApi api) {
|
public JavacordWrapper(DiscordApi api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.contextObjectProvider = new JavacordContextObjectProvider();
|
|
||||||
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
||||||
logger.info("Javacord wrapper loaded!");
|
logger.info("Javacord wrapper loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionType getInteractionType(Object context) {
|
public InteractionType getInteractionType(Object context) {
|
||||||
if (AutocompleteInteraction.class.isAssignableFrom(context.getClass()))
|
|
||||||
return InteractionType.AUTOCOMPLETE;
|
|
||||||
if (ApplicationCommandInteraction.class.isAssignableFrom(context.getClass()))
|
if (ApplicationCommandInteraction.class.isAssignableFrom(context.getClass()))
|
||||||
return InteractionType.COMMAND;
|
return InteractionType.COMMAND;
|
||||||
if (ButtonInteraction.class.isAssignableFrom(context.getClass()))
|
if (ButtonInteraction.class.isAssignableFrom(context.getClass()))
|
||||||
return InteractionType.BUTTON;
|
return InteractionType.BUTTON;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +72,22 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
api.bulkOverwriteGlobalApplicationCommands(globalCommands);
|
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
|
@Override
|
||||||
public ExecutableSlashCommandDefinition getCommandDefinition(Object context) {
|
public ExecutableSlashCommandDefinition getCommandDefinition(Object context) {
|
||||||
if (!(context instanceof SlashCommandInteraction))
|
if (!(context instanceof SlashCommandInteraction))
|
||||||
@ -119,53 +127,44 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
|
|
||||||
private org.javacord.api.interaction.SlashCommandOption convertSubCommandGroupDef(SlashCommandDefinition def, SubCommandGroup subGroup) {
|
private org.javacord.api.interaction.SlashCommandOption convertSubCommandGroupDef(SlashCommandDefinition def, SubCommandGroup subGroup) {
|
||||||
SubCommand[] subCommands = def.getSubCommands(subGroup.name());
|
SubCommand[] subCommands = def.getSubCommands(subGroup.name());
|
||||||
List<org.javacord.api.interaction.SlashCommandOption> convertedSubCommands = Arrays.stream(subCommands).map(this::convertSubCommandDef).toList();
|
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(
|
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND_GROUP, subGroup.name(), subGroup.description(), Arrays.asList(convertedSubCommands));
|
||||||
org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND_GROUP,
|
|
||||||
subGroup.name(),
|
|
||||||
subGroup.description(),
|
|
||||||
convertedSubCommands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private org.javacord.api.interaction.SlashCommandOption convertSubCommandDef(SubCommand sub) {
|
private org.javacord.api.interaction.SlashCommandOption convertSubCommandDef(SubCommand sub) {
|
||||||
List<org.javacord.api.interaction.SlashCommandOption> convertedOptions = Arrays.stream(sub.options()).map(this::convertOptionDef).toList();
|
List<org.javacord.api.interaction.SlashCommandOption> convertedOptions = new ArrayList<>();
|
||||||
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(
|
Arrays.stream(sub.options()).map(this::convertOptionDef).forEach(convertedOptions::add);
|
||||||
org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND,
|
return org.javacord.api.interaction.SlashCommandOption.createWithOptions(org.javacord.api.interaction.SlashCommandOptionType.SUB_COMMAND, sub.name(), sub.description(), convertedOptions);
|
||||||
sub.name(),
|
|
||||||
sub.description(),
|
|
||||||
convertedOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private org.javacord.api.interaction.SlashCommandOption convertOptionDef(SlashCommandOption option) {
|
private org.javacord.api.interaction.SlashCommandOption convertOptionDef(SlashCommandOption option) {
|
||||||
SlashCommandOptionType type = SlashCommandOptionType.fromValue(option.type().getValue());
|
org.javacord.api.interaction.SlashCommandOptionType type = Enum.valueOf(org.javacord.api.interaction.SlashCommandOptionType.class, option.type().toString());
|
||||||
SlashCommandOptionBuilder builder = new SlashCommandOptionBuilder();
|
return org.javacord.api.interaction.SlashCommandOption.create(type, option.name(), option.description(), option.required());
|
||||||
builder
|
|
||||||
.setType(type)
|
|
||||||
.setName(option.name())
|
|
||||||
.setDescription(option.description())
|
|
||||||
.setRequired(option.required())
|
|
||||||
.setAutocompletable(option.autocomplete())
|
|
||||||
.setChoices(convertChoices(option));
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<org.javacord.api.interaction.SlashCommandOptionChoice> convertChoices(SlashCommandOption option) {
|
private Object getOptionValue(SlashCommandInteractionOption option, SlashCommandOptionType type) {
|
||||||
List<org.javacord.api.interaction.SlashCommandOptionChoice> convertedChoices = new ArrayList<>();
|
switch (type) {
|
||||||
for (SlashCommandOptionChoice choice : ExecutableSlashCommandDefinition.getActualChoices(option)) {
|
case ATTACHMENT:
|
||||||
SlashCommandOptionChoiceBuilder builder = new SlashCommandOptionChoiceBuilder();
|
return option.getAttachmentValue().get();
|
||||||
builder.setName(choice.name());
|
case BOOLEAN:
|
||||||
if (choice.longValue() != Long.MAX_VALUE)
|
return option.getBooleanValue().get();
|
||||||
builder.setValue(choice.longValue());
|
case CHANNEL:
|
||||||
/*
|
return option.getChannelValue().get();
|
||||||
not yet available
|
case DECIMAL:
|
||||||
if (choice.doubleValue() != Double.MAX_VALUE)
|
return option.getDecimalValue().get();
|
||||||
builder.setValue(choice.doubleValue());
|
case LONG:
|
||||||
*/
|
return option.getLongValue().get();
|
||||||
if (!choice.stringValue().isEmpty())
|
case MENTIONABLE:
|
||||||
builder.setValue(choice.stringValue());
|
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;
|
||||||
}
|
}
|
||||||
return convertedChoices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -175,8 +174,20 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextObjectProvider getContextObjectProvider() {
|
public Object getComponentContextObject(Object context, Class<?> type) {
|
||||||
return contextObjectProvider;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -20,8 +20,7 @@ public class TestCommand implements InteractionHandler {
|
|||||||
@SlashCommandOption(
|
@SlashCommandOption(
|
||||||
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
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,179 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -41,52 +41,52 @@ public class SlashCommandInteractionOptionMock implements SlashCommandInteractio
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Long> getLongValue() {
|
public Optional<Long> getLongValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getLongValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Boolean> getBooleanValue() {
|
public Optional<Boolean> getBooleanValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getBooleanValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<User> getUserValue() {
|
public Optional<User> getUserValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getUserValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<CompletableFuture<User>> requestUserValue() {
|
public Optional<CompletableFuture<User>> requestUserValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'requestUserValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ServerChannel> getChannelValue() {
|
public Optional<ServerChannel> getChannelValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getChannelValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Attachment> getAttachmentValue() {
|
public Optional<Attachment> getAttachmentValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getAttachmentValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Role> getRoleValue() {
|
public Optional<Role> getRoleValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getRoleValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Mentionable> getMentionableValue() {
|
public Optional<Mentionable> getMentionableValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getMentionableValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Double> getDecimalValue() {
|
public Optional<Double> getDecimalValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'getDecimalValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<CompletableFuture<Mentionable>> requestMentionableValue() {
|
public Optional<CompletableFuture<Mentionable>> requestMentionableValue() {
|
||||||
return Optional.empty();
|
throw new UnsupportedOperationException("Unimplemented method 'requestMentionableValue'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user