Compare commits
No commits in common. "9f87f47b1ff8c5f25340efb1d19b6064e0f0b1b0" and "6bd6021b8642d9518310f3486e0afe169ff9a33a" have entirely different histories.
9f87f47b1f
...
6bd6021b86
@ -2,12 +2,16 @@
|
||||
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
|
||||
|
||||
[versions]
|
||||
commons-math3 = "3.6.1"
|
||||
guava = "33.0.0-jre"
|
||||
junit-jupiter = "5.10.2"
|
||||
log4j = "2.24.1"
|
||||
javacord = "3.8.0"
|
||||
geantyref = "2.0.0"
|
||||
|
||||
[libraries]
|
||||
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
|
||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
log4j = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j"}
|
||||
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
||||
|
@ -1,13 +1,24 @@
|
||||
package net.tomatentum.marinara;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import net.tomatentum.marinara.registry.InteractionRegistry;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
|
||||
public class Marinara {
|
||||
|
||||
public static <T extends LibraryWrapper> Marinara load(LibraryWrapper wrapper) {
|
||||
public static <T extends LibraryWrapper> Marinara load(Class<T> clazz) {
|
||||
try {
|
||||
Constructor<T> ctor = clazz.getConstructor();
|
||||
ctor.setAccessible(true);
|
||||
T wrapper = ctor.newInstance();
|
||||
InteractionRegistry registry = new InteractionRegistry(wrapper);
|
||||
return new Marinara(registry);
|
||||
}catch (Exception ex) {
|
||||
System.err.println(ex);
|
||||
System.exit(100);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private InteractionRegistry registry;
|
||||
|
@ -12,7 +12,7 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||
public class SlashCommandDefinition {
|
||||
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
||||
private SlashCommand slashCommand;
|
||||
private boolean isRootCommand;
|
||||
private boolean isRootCommand = false;
|
||||
|
||||
public SlashCommandDefinition(SlashCommand applicationCommand) {
|
||||
this.executableDefinitons = new ArrayList<>();
|
||||
@ -23,14 +23,16 @@ public class SlashCommandDefinition {
|
||||
if (def.applicationCommand() != null) {
|
||||
if (slashCommand == null)
|
||||
this.slashCommand = def.applicationCommand();
|
||||
if (!this.slashCommand.name().equals(def.applicationCommand().name()))
|
||||
if (!this.slashCommand.equals(def.applicationCommand()))
|
||||
throw new IllegalArgumentException(def + ": has a non matching Application Command description. Please edit it to equal all other descriptions or remove it to use other definitions descriptions");
|
||||
}
|
||||
|
||||
if (executableDefinitons.isEmpty())
|
||||
this.isRootCommand = def.isRootCommand();
|
||||
|
||||
if ((isRootCommand && !def.isRootCommand()) || (!isRootCommand && def.isRootCommand())) {
|
||||
if (isRootCommand) {
|
||||
if (!def.isRootCommand())
|
||||
throw new IllegalArgumentException(def + ": cannot have subcommands and rootcommand definitions together");
|
||||
long subCommandAmount = executableDefinitons.stream()
|
||||
.filter((x) -> !x.isRootCommand())
|
||||
.count();
|
||||
if (subCommandAmount > 0)
|
||||
throw new IllegalArgumentException(def + ": cannot have subcommands and rootcommand definitions together");
|
||||
}
|
||||
|
||||
@ -51,7 +53,7 @@ public class SlashCommandDefinition {
|
||||
subCommandGroupMap.put(x.name(), x);
|
||||
});
|
||||
|
||||
return subCommandGroupMap.values().toArray(new SubCommandGroup[0]);
|
||||
return (SubCommandGroup[]) subCommandGroupMap.values().toArray();
|
||||
}
|
||||
|
||||
public SubCommand[] getSubCommands(String groupName) {
|
||||
@ -74,7 +76,7 @@ public class SlashCommandDefinition {
|
||||
subCommandMap.put(x.name(), x);
|
||||
});
|
||||
|
||||
return subCommandMap.values().toArray(new SubCommand[0]);
|
||||
return (SubCommand[]) subCommandMap.values().toArray();
|
||||
}
|
||||
|
||||
public SlashCommand getFullSlashCommand() {
|
||||
|
@ -3,7 +3,6 @@ package net.tomatentum.marinara.registry;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
@ -19,7 +18,6 @@ public class InteractionRegistry {
|
||||
private LibraryWrapper wrapper;
|
||||
|
||||
public InteractionRegistry(LibraryWrapper wrapper) {
|
||||
this.interactionMethods = new ArrayList<>();
|
||||
this.wrapper = wrapper;
|
||||
wrapper.subscribeInteractions(this::handle);
|
||||
}
|
||||
@ -33,7 +31,6 @@ public class InteractionRegistry {
|
||||
public void registerCommands() {
|
||||
List<SlashCommandDefinition> defs = new ArrayList<>();
|
||||
List<ExecutableSlashCommandDefinition> execDefs = interactionMethods.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter((x) -> x.getClass().isAssignableFrom(SlashCommandInteractionMethod.class))
|
||||
.map((x) -> ((SlashCommandInteractionMethod)x).getCommandDefinition())
|
||||
.toList();
|
||||
|
@ -30,8 +30,8 @@ public final class ReflectionUtil {
|
||||
if (!isAnnotationPresent(method, SlashCommand.class))
|
||||
throw new RuntimeException(method.getName() + ": Missing ApplicationCommand Annotation on either Class or Method");
|
||||
|
||||
if ((method.isAnnotationPresent(SubCommand.class) &&
|
||||
!isAnnotationPresent(method, SlashCommand.class))) {
|
||||
if (!(method.isAnnotationPresent(SubCommand.class) &&
|
||||
isAnnotationPresent(method, SlashCommand.class))) {
|
||||
throw new RuntimeException(method.getName() + ": Missing ApplicationCommand Annotation on either Method or Class");
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
package net.tomatentum.marinara.test;
|
||||
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.tomatentum.marinara.Marinara;
|
||||
import net.tomatentum.marinare.wrapper.javacord.JavacordWrapper;
|
||||
|
||||
public class SlashCommandTest {
|
||||
|
||||
String DISCORD_TOKEN = System.getenv("DISCORD_TEST_TOKEN");
|
||||
|
||||
@Test
|
||||
public void testSlashCommand() {
|
||||
DiscordApi api = new DiscordApiBuilder()
|
||||
.setToken(DISCORD_TOKEN)
|
||||
.login().join();
|
||||
Marinara marinara = Marinara.load(new JavacordWrapper(api));
|
||||
marinara.getRegistry().addInteractions(new TestCommand());
|
||||
marinara.getRegistry().registerCommands();
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package net.tomatentum.marinara.test;
|
||||
|
||||
import org.javacord.api.interaction.SlashCommandInteraction;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
||||
import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType;
|
||||
|
||||
public class TestCommand implements InteractionHandler {
|
||||
@SlashCommand(
|
||||
name = "test",
|
||||
description = "testingen",
|
||||
serverIds = {
|
||||
1037753048602255440L
|
||||
},
|
||||
options = {
|
||||
@SlashCommandOption(
|
||||
name = "pommes",
|
||||
description = "mit Fett",
|
||||
type = SlashCommandOptionType.MENTIONABLE
|
||||
)
|
||||
}
|
||||
)
|
||||
public void exec(SlashCommandInteraction interaction) {
|
||||
System.out.println("Success!");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user