Compare commits
No commits in common. "42a675dc967df727df24fa542fbd2c8f411b1c9a" and "83b446e6fb6ff64fd819085b19bf0fc817a99d27" have entirely different histories.
42a675dc96
...
83b446e6fb
@ -8,7 +8,7 @@ javacord = "3.8.0"
|
|||||||
discord4j = "3.2.7"
|
discord4j = "3.2.7"
|
||||||
geantyref = "2.0.0"
|
geantyref = "2.0.0"
|
||||||
mockito = "5.15.2"
|
mockito = "5.15.2"
|
||||||
cutin = "0.2.0"
|
cutin = "0.1.1-cad019e"
|
||||||
|
|
||||||
[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" }
|
||||||
@ -18,4 +18,4 @@ javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
|||||||
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
|
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"}
|
||||||
mockito = {module = "org.mockito:mockito-core", version.ref = "mockito"}
|
mockito = {module = "org.mockito:mockito-core", version.ref = "mockito"}
|
||||||
cutin = {module = "net.tomatentum.cutin:lib", version.ref = "cutin"}
|
cutin = {module = "net.tomatentum.cutin:lib-dev", version.ref = "cutin"}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.tomatentum.marinara.checks;
|
package net.tomatentum.marinara.checks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.MethodParser;
|
import net.tomatentum.cutin.MethodParser;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory.ParserResults;
|
|
||||||
import net.tomatentum.cutin.container.MethodContainer;
|
import net.tomatentum.cutin.container.MethodContainer;
|
||||||
import net.tomatentum.cutin.method.BestCandidateMethod;
|
import net.tomatentum.cutin.method.BestCandidateMethod;
|
||||||
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier.CheckMethodType;
|
import net.tomatentum.marinara.checks.CheckMethodIdentifier.CheckMethodType;
|
||||||
import net.tomatentum.marinara.parser.InteractionCheckClassParser;
|
import net.tomatentum.marinara.parser.InteractionCheckClassParser;
|
||||||
|
|
||||||
@ -14,13 +14,8 @@ public class InteractionCheckMethod extends BestCandidateMethod<CheckMethodIdent
|
|||||||
|
|
||||||
private CheckMethodIdentifier identifier;
|
private CheckMethodIdentifier identifier;
|
||||||
|
|
||||||
public InteractionCheckMethod(
|
public InteractionCheckMethod(String methodName, Object containingObject) {
|
||||||
String methodName,
|
|
||||||
Object containingObject,
|
|
||||||
CheckMethodIdentifier identifier
|
|
||||||
) {
|
|
||||||
super(methodName, containingObject);
|
super(methodName, containingObject);
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,24 +44,21 @@ public class InteractionCheckMethod extends BestCandidateMethod<CheckMethodIdent
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void addParser(Set<MethodParser> parsers) {
|
public void addParser(ReflectedMethod<CheckMethodIdentifier, CheckExecutionContext> method, List<MethodParser> parsers) {
|
||||||
parsers.add(
|
parsers.add(
|
||||||
new InteractionCheckClassParser()
|
new InteractionCheckClassParser((Class<InteractionCheck<?>>) method.containingObject().getClass(),
|
||||||
|
a -> ((InteractionCheckMethod) method).identifier = new CheckMethodIdentifier(a, type))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Optional<BestCandidateMethod<CheckMethodIdentifier, CheckExecutionContext>> bcProduce(
|
protected Optional<BestCandidateMethod<CheckMethodIdentifier, CheckExecutionContext>> bcProduce(String methodName,
|
||||||
String methodName,
|
Object containingObject) {
|
||||||
Object containingObject,
|
if (!(containingObject instanceof InteractionCheck))
|
||||||
ParserResults parserResults
|
return Optional.empty();
|
||||||
) {
|
return Optional.of(new InteractionCheckMethod(methodName, containingObject));
|
||||||
|
|
||||||
CheckMethodIdentifier identifier = new CheckMethodIdentifier(parserResults.get(InteractionCheckClassParser.class), type);
|
|
||||||
if (identifier.annotationType() == null)
|
|
||||||
return null;
|
|
||||||
return Optional.of(new InteractionCheckMethod(methodName, containingObject, identifier));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,18 @@ package net.tomatentum.marinara.interaction.components.methods;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.MethodParser;
|
import net.tomatentum.cutin.MethodParser;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory.ParserResults;
|
|
||||||
import net.tomatentum.cutin.container.MethodContainer;
|
import net.tomatentum.cutin.container.MethodContainer;
|
||||||
import net.tomatentum.cutin.method.ReflectedMethod;
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||||
import net.tomatentum.marinara.checks.AppliedCheck;
|
|
||||||
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
||||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
||||||
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.Button;
|
||||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||||
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
||||||
import net.tomatentum.marinara.parser.ButtonParser;
|
import net.tomatentum.marinara.parser.ButtonParser;
|
||||||
import net.tomatentum.marinara.parser.InteractionCheckParser;
|
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
|
|
||||||
public class ButtonInteractionMethod extends InteractionMethod {
|
public class ButtonInteractionMethod extends InteractionMethod {
|
||||||
@ -25,15 +22,8 @@ public class ButtonInteractionMethod extends InteractionMethod {
|
|||||||
private String customId;
|
private String customId;
|
||||||
private ContextObjectProvider cop;
|
private ContextObjectProvider cop;
|
||||||
|
|
||||||
private ButtonInteractionMethod(
|
private ButtonInteractionMethod(Method method, InteractionHandler handler, ContextObjectProvider cop) {
|
||||||
Method method,
|
super(method, handler);
|
||||||
InteractionHandler handler,
|
|
||||||
List<AppliedCheck> appliedChecks,
|
|
||||||
String customId,
|
|
||||||
ContextObjectProvider cop
|
|
||||||
) {
|
|
||||||
super(method, handler, appliedChecks);
|
|
||||||
this.customId = customId;
|
|
||||||
this.cop = cop;
|
this.cop = cop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,25 +56,22 @@ public class ButtonInteractionMethod extends InteractionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject, ParserResults parserResults) {
|
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject) {
|
||||||
if (!(containingObject instanceof InteractionHandler)) return Optional.empty();
|
ButtonInteractionMethod rMethod = null;
|
||||||
String customId = parserResults.get(ButtonParser.class);
|
if (method.isAnnotationPresent(Button.class) &&
|
||||||
if (customId == null) return Optional.empty();
|
(containingObject instanceof InteractionHandler iHandler)
|
||||||
return Optional.of(new ButtonInteractionMethod(
|
)
|
||||||
method,
|
rMethod = new ButtonInteractionMethod(method, iHandler, this.cop);
|
||||||
(InteractionHandler) containingObject,
|
|
||||||
parserResults.get(InteractionCheckParser.class),
|
return Optional.ofNullable(rMethod);
|
||||||
customId,
|
|
||||||
this.cop
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addParser(Set<MethodParser> parser) {
|
public void addParser(ReflectedMethod<InteractionIdentifier, Object> method, List<MethodParser> parser) {
|
||||||
super.addParser(parser);
|
super.addParser(method, parser);
|
||||||
|
|
||||||
parser.add(
|
parser.add(
|
||||||
new ButtonParser()
|
new ButtonParser(method.method(), x -> ((ButtonInteractionMethod) method).customId = x)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,20 +3,19 @@ package net.tomatentum.marinara.interaction.methods;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.MethodParser;
|
import net.tomatentum.cutin.MethodParser;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory.ParserResults;
|
|
||||||
import net.tomatentum.cutin.container.MethodContainer;
|
import net.tomatentum.cutin.container.MethodContainer;
|
||||||
import net.tomatentum.cutin.method.ReflectedMethod;
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||||
import net.tomatentum.marinara.checks.AppliedCheck;
|
|
||||||
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
||||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
||||||
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.commands.annotation.SlashCommand;
|
||||||
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||||
import net.tomatentum.marinara.parser.AutocompleteParser;
|
import net.tomatentum.marinara.parser.AutocompleteParser;
|
||||||
import net.tomatentum.marinara.parser.InteractionCheckParser;
|
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
|
|
||||||
public class AutoCompleteInteractionMethod extends InteractionMethod {
|
public class AutoCompleteInteractionMethod extends InteractionMethod {
|
||||||
@ -24,15 +23,11 @@ public class AutoCompleteInteractionMethod extends InteractionMethod {
|
|||||||
private String autocompleteRef;
|
private String autocompleteRef;
|
||||||
private ContextObjectProvider cop;
|
private ContextObjectProvider cop;
|
||||||
|
|
||||||
private AutoCompleteInteractionMethod(
|
private AutoCompleteInteractionMethod(Method method,
|
||||||
Method method,
|
InteractionHandler handler,
|
||||||
InteractionHandler handler,
|
ContextObjectProvider cop
|
||||||
List<AppliedCheck> appliedChecks,
|
|
||||||
String autocompleteRef,
|
|
||||||
ContextObjectProvider cop
|
|
||||||
) {
|
) {
|
||||||
super(method, handler, appliedChecks);
|
super(method, handler);
|
||||||
this.autocompleteRef = autocompleteRef;
|
|
||||||
this.cop = cop;
|
this.cop = cop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,27 +64,23 @@ public class AutoCompleteInteractionMethod extends InteractionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject, ParserResults parserResults) {
|
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject) {
|
||||||
if (!(containingObject instanceof InteractionHandler)) return Optional.empty();
|
AutoCompleteInteractionMethod rMethod = null;
|
||||||
String[] autocompletes = parserResults.get(AutocompleteParser.class);
|
if ((containingObject instanceof InteractionHandler iHandler) &&
|
||||||
if (autocompletes.length <= 0) return Optional.empty();
|
method.isAnnotationPresent(AutoComplete.class) &&
|
||||||
|
!(method.isAnnotationPresent(SlashCommand.class) ||
|
||||||
return Optional.of(new AutoCompleteInteractionMethod(
|
method.isAnnotationPresent(SubCommand.class)))
|
||||||
method,
|
rMethod = new AutoCompleteInteractionMethod(method, iHandler, cop);
|
||||||
(InteractionHandler) containingObject,
|
|
||||||
parserResults.get(InteractionCheckParser.class),
|
|
||||||
autocompletes[0],
|
|
||||||
cop
|
|
||||||
));
|
|
||||||
|
|
||||||
|
return Optional.ofNullable(rMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addParser(Set<MethodParser> parser) {
|
public void addParser(ReflectedMethod<InteractionIdentifier, Object> method, List<MethodParser> parser) {
|
||||||
super.addParser(parser);
|
super.addParser(method, parser);
|
||||||
|
|
||||||
parser.add(
|
parser.add(
|
||||||
new AutocompleteParser()
|
new AutocompleteParser(method.method(), x -> ((AutoCompleteInteractionMethod) method).autocompleteRef = x[0])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.tomatentum.marinara.interaction.methods;
|
package net.tomatentum.marinara.interaction.methods;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.MethodParser;
|
import net.tomatentum.cutin.MethodParser;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory;
|
import net.tomatentum.cutin.ReflectedMethodFactory;
|
||||||
@ -21,11 +21,10 @@ public abstract class InteractionMethod extends ReflectedMethod<InteractionIdent
|
|||||||
|
|
||||||
protected InteractionMethod(
|
protected InteractionMethod(
|
||||||
Method method,
|
Method method,
|
||||||
InteractionHandler handler,
|
InteractionHandler handler
|
||||||
List<AppliedCheck> appliedChecks
|
|
||||||
) {
|
) {
|
||||||
super(method, handler);
|
super(method, handler);
|
||||||
this.appliedChecks = appliedChecks;
|
this.appliedChecks = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,9 +60,10 @@ public abstract class InteractionMethod extends ReflectedMethod<InteractionIdent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addParser(Set<MethodParser> parser) {
|
public void addParser(ReflectedMethod<InteractionIdentifier, Object> method, List<MethodParser> parser) {
|
||||||
|
InteractionMethod imethod = (InteractionMethod) method;
|
||||||
parser.add(
|
parser.add(
|
||||||
new InteractionCheckParser(this.checkContainer)
|
new InteractionCheckParser(method.method(), imethod.appliedChecks::add, this.checkContainer)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,36 +3,27 @@ package net.tomatentum.marinara.interaction.methods;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.MethodParser;
|
import net.tomatentum.cutin.MethodParser;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory.ParserResults;
|
|
||||||
import net.tomatentum.cutin.container.MethodContainer;
|
import net.tomatentum.cutin.container.MethodContainer;
|
||||||
import net.tomatentum.cutin.method.ReflectedMethod;
|
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||||
import net.tomatentum.marinara.checks.AppliedCheck;
|
|
||||||
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
||||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
||||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||||
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||||
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||||
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||||
import net.tomatentum.marinara.parser.InteractionCheckParser;
|
|
||||||
import net.tomatentum.marinara.parser.SlashCommandParser;
|
import net.tomatentum.marinara.parser.SlashCommandParser;
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
|
|
||||||
public class SlashCommandInteractionMethod extends InteractionMethod {
|
public class SlashCommandInteractionMethod extends InteractionMethod {
|
||||||
|
|
||||||
private SlashCommandIdentifier identifier;
|
private SlashCommandIdentifier interactionIdentifier;
|
||||||
private ContextObjectProvider cop;
|
private ContextObjectProvider cop;
|
||||||
|
|
||||||
private SlashCommandInteractionMethod(
|
private SlashCommandInteractionMethod(Method method, InteractionHandler handler, ContextObjectProvider cop) {
|
||||||
Method method,
|
super(method, handler);
|
||||||
InteractionHandler handler,
|
|
||||||
List<AppliedCheck> appliedChecks,
|
|
||||||
SlashCommandIdentifier identifier,
|
|
||||||
ContextObjectProvider cop
|
|
||||||
) {
|
|
||||||
super(method, handler, appliedChecks);
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.cop = cop;
|
this.cop = cop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +31,14 @@ public class SlashCommandInteractionMethod extends InteractionMethod {
|
|||||||
public Object getParameter(Object context, int index) {
|
public Object getParameter(Object context, int index) {
|
||||||
Object superResult = super.getParameter(context, index);
|
Object superResult = super.getParameter(context, index);
|
||||||
if (superResult == null)
|
if (superResult == null)
|
||||||
return this.cop.convertCommandOption(context, identifier.options()[index-1].name());
|
return this.cop.convertCommandOption(context, interactionIdentifier.options()[index-1].name());
|
||||||
else
|
else
|
||||||
return superResult;
|
return superResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionIdentifier identifier() {
|
public InteractionIdentifier identifier() {
|
||||||
return identifier;
|
return interactionIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory extends InteractionMethod.Factory {
|
public static class Factory extends InteractionMethod.Factory {
|
||||||
@ -60,25 +51,21 @@ public class SlashCommandInteractionMethod extends InteractionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject, ParserResults parserResults) {
|
public Optional<ReflectedMethod<InteractionIdentifier, Object>> produce(Method method, Object containingObject) {
|
||||||
if (!(containingObject instanceof InteractionHandler)) return Optional.empty();
|
SlashCommandInteractionMethod rMethod = null;
|
||||||
SlashCommandIdentifier ident = parserResults.get(SlashCommandParser.class);
|
if ((containingObject instanceof InteractionHandler iHandler) &&
|
||||||
if (ident == null) return Optional.empty();
|
(method.isAnnotationPresent(SlashCommand.class) ||
|
||||||
return Optional.of(new SlashCommandInteractionMethod(
|
method.isAnnotationPresent(SubCommand.class)))
|
||||||
method,
|
rMethod = new SlashCommandInteractionMethod(method, iHandler, cop);
|
||||||
(InteractionHandler) containingObject,
|
return Optional.ofNullable(rMethod);
|
||||||
parserResults.get(InteractionCheckParser.class),
|
|
||||||
ident,
|
|
||||||
cop
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addParser(Set<MethodParser> parser) {
|
public void addParser(ReflectedMethod<InteractionIdentifier, Object> method, List<MethodParser> parser) {
|
||||||
super.addParser(parser);
|
super.addParser(method, parser);
|
||||||
|
|
||||||
parser.add(
|
parser.add(
|
||||||
new SlashCommandParser()
|
new SlashCommandParser(method.method(), x -> ((SlashCommandInteractionMethod) method).interactionIdentifier = x)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.tomatentum.marinara.parser;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -14,14 +15,21 @@ public class AutocompleteParser implements MethodParser {
|
|||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
private Method method;
|
||||||
|
private Consumer<String[]> consumer;
|
||||||
|
|
||||||
|
public AutocompleteParser(Method method, Consumer<String[]> consumer) {
|
||||||
|
this.method = method;
|
||||||
|
this.consumer = consumer;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(Method method, Object containingObject) {
|
public void parse() {
|
||||||
String[] autoCompletes = Arrays.stream(method.getAnnotationsByType(AutoComplete.class))
|
String[] autocompletes = Arrays.stream(this.method.getAnnotationsByType(AutoComplete.class))
|
||||||
.map(AutoComplete::value)
|
.map(AutoComplete::value)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
if (autoCompletes.length > 0)
|
logger.trace("Parsed AutoComplete annotation {} for method {}", autocompletes, ReflectionUtil.getFullMethodName(method));
|
||||||
logger.trace("Parsed AutoComplete annotations {} for method {}", autoCompletes, ReflectionUtil.getFullMethodName(method));
|
this.consumer.accept(autocompletes);
|
||||||
return autoCompletes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.tomatentum.marinara.parser;
|
package net.tomatentum.marinara.parser;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -11,17 +12,21 @@ import net.tomatentum.marinara.interaction.annotation.Button;
|
|||||||
|
|
||||||
public class ButtonParser implements MethodParser {
|
public class ButtonParser implements MethodParser {
|
||||||
|
|
||||||
|
private Method method;
|
||||||
|
private Consumer<String> consumer;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
public ButtonParser() {
|
public ButtonParser(Method method, Consumer<String> consumer) {
|
||||||
|
this.method = method;
|
||||||
|
this.consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(Method method, Object containingObject) {
|
public void parse() {
|
||||||
Button button = method.getAnnotation(Button.class);
|
Button button = this.method.getAnnotation(Button.class);
|
||||||
if (button == null) return null;
|
|
||||||
logger.trace("Parsed Button annotation {} for method {}", button, ReflectionUtil.getFullMethodName(method));
|
logger.trace("Parsed Button annotation {} for method {}", button, ReflectionUtil.getFullMethodName(method));
|
||||||
return button.value();
|
this.consumer.accept(button.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.tomatentum.marinara.parser;
|
package net.tomatentum.marinara.parser;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -15,14 +15,20 @@ public class InteractionCheckClassParser implements MethodParser {
|
|||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
private Class<? extends InteractionCheck<?>> interactionCheckType;
|
||||||
|
private Consumer<Type> annotationTypeConsumer;
|
||||||
|
|
||||||
|
public InteractionCheckClassParser(Class<? extends InteractionCheck<?>> interactionCheckType, Consumer<Type> annotationTypeConsumer) {
|
||||||
|
this.interactionCheckType = interactionCheckType;
|
||||||
|
this.annotationTypeConsumer = annotationTypeConsumer;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(Method method, Object containingObject) {
|
public void parse() {
|
||||||
ParameterizedType type = (ParameterizedType) GenericTypeReflector.getExactSuperType(containingObject.getClass(), InteractionCheck.class);
|
ParameterizedType type = (ParameterizedType) GenericTypeReflector.getExactSuperType(interactionCheckType, InteractionCheck.class);
|
||||||
if (type == null) return null;
|
Type typeParam = type.getActualTypeArguments()[0];
|
||||||
Type typeParam = type.getActualTypeArguments().length == 1 ? type.getActualTypeArguments()[0] : null;
|
logger.trace("Parsed InteractionCheck Annotation {}", typeParam);
|
||||||
if (typeParam != null)
|
this.annotationTypeConsumer.accept(typeParam);
|
||||||
logger.trace("Parsed InteractionCheck Annotation {}", typeParam);
|
|
||||||
return typeParam;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package net.tomatentum.marinara.parser;
|
|||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -19,31 +19,31 @@ import net.tomatentum.marinara.checks.CheckMethodIdentifier.CheckMethodType;
|
|||||||
public class InteractionCheckParser implements MethodParser {
|
public class InteractionCheckParser implements MethodParser {
|
||||||
|
|
||||||
private MethodContainer<CheckMethodIdentifier, CheckExecutionContext> checkContainer;
|
private MethodContainer<CheckMethodIdentifier, CheckExecutionContext> checkContainer;
|
||||||
|
private Method method;
|
||||||
|
private Consumer<AppliedCheck> consumer;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
public InteractionCheckParser(MethodContainer<CheckMethodIdentifier, CheckExecutionContext> checkContainer) {
|
public InteractionCheckParser(Method method, Consumer<AppliedCheck> consumer, MethodContainer<CheckMethodIdentifier, CheckExecutionContext> checkContainer) {
|
||||||
this.checkContainer = checkContainer;
|
this.checkContainer = checkContainer;
|
||||||
|
this.method = method;
|
||||||
|
this.consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(Method method, Object containingObject) {
|
public void parse() {
|
||||||
Annotation[] annotations = method.getAnnotations();
|
Annotation[] annotations = method.getAnnotations();
|
||||||
return Arrays.stream(annotations)
|
Arrays.stream(annotations).forEach(this::convertAnnotation);
|
||||||
.map(a -> convertAnnotation(a, method))
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppliedCheck convertAnnotation(Annotation annotation, Method method) {
|
private void convertAnnotation(Annotation annotation) {
|
||||||
var preExec = this.checkContainer.findFirstFor(new CheckMethodIdentifier(annotation.annotationType(), CheckMethodType.PRE));
|
var preExec = this.checkContainer.findFirstFor(new CheckMethodIdentifier(annotation.annotationType(), CheckMethodType.PRE));
|
||||||
var postExec = this.checkContainer.findFirstFor(new CheckMethodIdentifier(annotation.annotationType(), CheckMethodType.POST));
|
var postExec = this.checkContainer.findFirstFor(new CheckMethodIdentifier(annotation.annotationType(), CheckMethodType.POST));
|
||||||
if (preExec.isPresent() && postExec.isPresent()) {
|
if (preExec.isPresent() && postExec.isPresent()) {
|
||||||
AppliedCheck appliedCheck = new AppliedCheck(annotation, preExec.get(), postExec.get());
|
AppliedCheck appliedCheck = new AppliedCheck(annotation, preExec.get(), postExec.get());
|
||||||
logger.trace("Parsed InteractionCheck {} for annotation {} for method {}", preExec.get().containingObject(), annotation, ReflectionUtil.getFullMethodName(method));
|
logger.trace("Parsed InteractionCheck {} for annotation {} for method {}", preExec.get().containingObject(), annotation, ReflectionUtil.getFullMethodName(method));
|
||||||
return appliedCheck;
|
consumer.accept(appliedCheck);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.tomatentum.marinara.parser;
|
package net.tomatentum.marinara.parser;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -12,17 +13,22 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
|||||||
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.ident.InteractionIdentifier;
|
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||||
|
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||||
|
|
||||||
public class SlashCommandParser implements MethodParser {
|
public class SlashCommandParser implements MethodParser {
|
||||||
|
|
||||||
|
private Method method;
|
||||||
|
private Consumer<SlashCommandIdentifier> consumer;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
public SlashCommandParser() {
|
public SlashCommandParser(Method method, Consumer<SlashCommandIdentifier> consumer) {
|
||||||
|
this.method = method;
|
||||||
|
this.consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(Method method, Object containingObject) {
|
public void parse() {
|
||||||
if (!method.isAnnotationPresent(SlashCommand.class) && !method.isAnnotationPresent(SubCommand.class)) return null;
|
|
||||||
this.checkValidCommandMethod(method);
|
this.checkValidCommandMethod(method);
|
||||||
|
|
||||||
SlashCommand cmd = ReflectionUtil.getAnnotation(method, SlashCommand.class);
|
SlashCommand cmd = ReflectionUtil.getAnnotation(method, SlashCommand.class);
|
||||||
@ -53,21 +59,21 @@ public class SlashCommandParser implements MethodParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.trace("Parsed using SlashCommandParser for method {} with the result: {}", ReflectionUtil.getFullMethodName(method), lastIdentifier);
|
logger.trace("Parsed using SlashCommandParser for method {} with the result: {}", ReflectionUtil.getFullMethodName(method), lastIdentifier);
|
||||||
return lastIdentifier;
|
consumer.accept((SlashCommandIdentifier) lastIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkValidCommandMethod(Method method) {
|
private void checkValidCommandMethod(Method method) {
|
||||||
if (method.isAnnotationPresent(SlashCommand.class) &&
|
if (method.isAnnotationPresent(SlashCommand.class) &&
|
||||||
method.getDeclaringClass().isAnnotationPresent(SlashCommand.class)) {
|
method.getDeclaringClass().isAnnotationPresent(SlashCommand.class)) {
|
||||||
throw new RuntimeException(method.getName() + ": Can't have SlashCommand Annotation on Class and Method");
|
throw new RuntimeException(method.getName() + ": Can't have ApplicationCommand Annotation on Class and Method");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ReflectionUtil.isAnnotationPresent(method, SlashCommand.class))
|
if (!ReflectionUtil.isAnnotationPresent(method, SlashCommand.class))
|
||||||
throw new RuntimeException(method.getName() + ": Missing SlashCommand Annotation on either Class or Method");
|
throw new RuntimeException(method.getName() + ": Missing ApplicationCommand Annotation on either Class or Method");
|
||||||
|
|
||||||
if ((method.isAnnotationPresent(SubCommand.class) &&
|
if ((method.isAnnotationPresent(SubCommand.class) &&
|
||||||
!ReflectionUtil.isAnnotationPresent(method, SlashCommand.class))) {
|
!ReflectionUtil.isAnnotationPresent(method, SlashCommand.class))) {
|
||||||
throw new RuntimeException(method.getName() + ": Missing SlashCommand Annotation on either Method or Class");
|
throw new RuntimeException(method.getName() + ": Missing ApplicationCommand Annotation on either Method or Class");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import discord4j.core.GatewayDiscordClient;
|
import discord4j.core.GatewayDiscordClient;
|
||||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||||
@ -14,6 +13,7 @@ import discord4j.core.object.command.ApplicationCommandOption.Type;
|
|||||||
import discord4j.discordjson.json.ApplicationCommandOptionChoiceData;
|
import discord4j.discordjson.json.ApplicationCommandOptionChoiceData;
|
||||||
import discord4j.discordjson.json.ApplicationCommandRequest;
|
import discord4j.discordjson.json.ApplicationCommandRequest;
|
||||||
|
|
||||||
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.wrapper.CommandConverter;
|
import net.tomatentum.marinara.wrapper.CommandConverter;
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
@ -37,7 +37,7 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
private Discord4JContextObjectProvider contextObjectProvider;
|
private Discord4JContextObjectProvider contextObjectProvider;
|
||||||
private CommandRegisterer<ApplicationCommandRequest> commandRegisterer;
|
private CommandRegisterer<ApplicationCommandRequest> commandRegisterer;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public Discord4JWrapper(GatewayDiscordClient api) {
|
public Discord4JWrapper(GatewayDiscordClient api) {
|
||||||
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
||||||
|
@ -21,7 +21,6 @@ import discord4j.core.object.command.ApplicationCommandOption.Type;
|
|||||||
import net.tomatentum.marinara.Marinara;
|
import net.tomatentum.marinara.Marinara;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||||
|
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
class SlashCommandTest {
|
class SlashCommandTest {
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ import org.javacord.api.interaction.AutocompleteInteraction;
|
|||||||
import org.javacord.api.interaction.SlashCommandBuilder;
|
import org.javacord.api.interaction.SlashCommandBuilder;
|
||||||
import org.javacord.api.interaction.SlashCommandOptionChoice;
|
import org.javacord.api.interaction.SlashCommandOptionChoice;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import net.tomatentum.marinara.wrapper.CommandConverter;
|
import net.tomatentum.marinara.wrapper.CommandConverter;
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||||
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.identifierconverter.AutocompleteIdentifierConverter;
|
import net.tomatentum.marinara.wrapper.javacord.identifierconverter.AutocompleteIdentifierConverter;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.identifierconverter.ButtonIdentifierConverter;
|
import net.tomatentum.marinara.wrapper.javacord.identifierconverter.ButtonIdentifierConverter;
|
||||||
@ -23,7 +23,7 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
private JavacordContextObjectProvider contextObjectProvider;
|
private JavacordContextObjectProvider contextObjectProvider;
|
||||||
private CommandRegisterer<SlashCommandBuilder> commandRegisterer;
|
private CommandRegisterer<SlashCommandBuilder> commandRegisterer;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public JavacordWrapper(DiscordApi api) {
|
public JavacordWrapper(DiscordApi api) {
|
||||||
this.contextObjectProvider = new JavacordContextObjectProvider();
|
this.contextObjectProvider = new JavacordContextObjectProvider();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user