rename to make more sense
This commit is contained in:
parent
fd749b31d8
commit
11ebb3fdea
@ -4,7 +4,7 @@ import net.tomatentum.marinara.interaction.commands.annotation.ApplicationComman
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.CommandOption;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||
|
||||
public record ExecutableCommandDefinition(
|
||||
public record ExecutableSlashCommandDefinition(
|
||||
ApplicationCommand applicationCommand,
|
||||
SubCommand subCommand,
|
||||
String[] subCommandGroups,
|
||||
@ -12,9 +12,9 @@ public record ExecutableCommandDefinition(
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof ExecutableCommandDefinition))
|
||||
if (!(o instanceof ExecutableSlashCommandDefinition))
|
||||
return false;
|
||||
ExecutableCommandDefinition other = (ExecutableCommandDefinition) o;
|
||||
ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o;
|
||||
return other.applicationCommand.name().equals(this.applicationCommand.name()) &&
|
||||
other.subCommandGroups.equals(this.subCommandGroups) &&
|
||||
other.subCommand.equals(this.subCommand);
|
||||
@ -38,11 +38,11 @@ public record ExecutableCommandDefinition(
|
||||
this.subCommandGroupNames = new String[0];
|
||||
}
|
||||
|
||||
public ExecutableCommandDefinition build() {
|
||||
public ExecutableSlashCommandDefinition build() {
|
||||
if (applicationCommand == null)
|
||||
throw new IllegalArgumentException("applicationCommandName cant be null");
|
||||
|
||||
return new ExecutableCommandDefinition(applicationCommand, subCommand, subCommandGroupNames, subCommand != null ? subCommand.options() : applicationCommand.options());
|
||||
return new ExecutableSlashCommandDefinition(applicationCommand, subCommand, subCommandGroupNames, subCommand != null ? subCommand.options() : applicationCommand.options());
|
||||
}
|
||||
|
||||
public void setApplicationCommand(ApplicationCommand applicationCommand) {
|
@ -6,18 +6,18 @@ import java.util.List;
|
||||
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand;
|
||||
|
||||
public class ApplicationCommandDefinition {
|
||||
private List<ExecutableCommandDefinition> executableDefinitons;
|
||||
public class SlashCommandDefinition {
|
||||
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
||||
private ApplicationCommand applicationCommand;
|
||||
private int subCommandGroupCount = -1;
|
||||
private boolean isRootCommand = false;
|
||||
|
||||
public ApplicationCommandDefinition(ApplicationCommand applicationCommand) {
|
||||
public SlashCommandDefinition(ApplicationCommand applicationCommand) {
|
||||
this.executableDefinitons = new ArrayList<>();
|
||||
this.applicationCommand = applicationCommand;
|
||||
}
|
||||
|
||||
public ApplicationCommandDefinition addExecutableCommand(ExecutableCommandDefinition def) {
|
||||
public SlashCommandDefinition addExecutableCommand(ExecutableSlashCommandDefinition def) {
|
||||
if (this.subCommandGroupCount == -1)
|
||||
this.subCommandGroupCount = def.subCommandGroups().length;
|
||||
if (def.subCommandGroups().length != subCommandGroupCount)
|
||||
@ -46,14 +46,14 @@ public class ApplicationCommandDefinition {
|
||||
return applicationCommand;
|
||||
}
|
||||
|
||||
public ExecutableCommandDefinition[] getExecutableDefinitons() {
|
||||
return executableDefinitons.toArray(new ExecutableCommandDefinition[0]);
|
||||
public ExecutableSlashCommandDefinition[] getExecutableDefinitons() {
|
||||
return executableDefinitons.toArray(new ExecutableSlashCommandDefinition[0]);
|
||||
}
|
||||
|
||||
public ExecutableCommandDefinition[] getUniqueExecutableDefinitions() {
|
||||
HashSet<ExecutableCommandDefinition> set = new HashSet<>();
|
||||
public ExecutableSlashCommandDefinition[] getUniqueExecutableDefinitions() {
|
||||
HashSet<ExecutableSlashCommandDefinition> set = new HashSet<>();
|
||||
executableDefinitons.forEach(set::add);
|
||||
return set.toArray(new ExecutableCommandDefinition[0]);
|
||||
return set.toArray(new ExecutableSlashCommandDefinition[0]);
|
||||
}
|
||||
public int getSubCommandGroupCount() {
|
||||
return subCommandGroupCount;
|
@ -4,7 +4,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||
@ -13,7 +13,7 @@ import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
|
||||
public class CommandInteractionMethod extends InteractionMethod {
|
||||
|
||||
private ExecutableCommandDefinition commandDefinition;
|
||||
private ExecutableSlashCommandDefinition commandDefinition;
|
||||
|
||||
CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
|
||||
super(method, handler, wrapper);
|
||||
@ -27,7 +27,7 @@ public class CommandInteractionMethod extends InteractionMethod {
|
||||
|
||||
@Override
|
||||
public boolean canRun(Object context) {
|
||||
ExecutableCommandDefinition other = wrapper.getCommandDefinition(context);
|
||||
ExecutableSlashCommandDefinition other = wrapper.getCommandDefinition(context);
|
||||
return commandDefinition.equals(other);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class CommandInteractionMethod extends InteractionMethod {
|
||||
return InteractionType.COMMAND;
|
||||
}
|
||||
|
||||
public ExecutableCommandDefinition getCommandDefinition() {
|
||||
public ExecutableSlashCommandDefinition getCommandDefinition() {
|
||||
return commandDefinition;
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class CommandInteractionMethod extends InteractionMethod {
|
||||
ReflectionUtil.checkValidCommandMethod(method);
|
||||
|
||||
ApplicationCommand cmd = ReflectionUtil.getAnnotation(method, ApplicationCommand.class);
|
||||
ExecutableCommandDefinition.Builder builder = new ExecutableCommandDefinition.Builder();
|
||||
ExecutableSlashCommandDefinition.Builder builder = new ExecutableSlashCommandDefinition.Builder();
|
||||
builder.setApplicationCommand(cmd);
|
||||
|
||||
if (ReflectionUtil.isAnnotationPresent(method, SubCommandGroup.class)) {
|
||||
|
@ -7,8 +7,8 @@ import java.util.Optional;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.commands.ApplicationCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.methods.CommandInteractionMethod;
|
||||
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
@ -29,23 +29,23 @@ public class InteractionRegistry {
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
List<ApplicationCommandDefinition> defs = new ArrayList<>();
|
||||
List<ExecutableCommandDefinition> execDefs = interactionMethods.stream()
|
||||
List<SlashCommandDefinition> defs = new ArrayList<>();
|
||||
List<ExecutableSlashCommandDefinition> execDefs = interactionMethods.stream()
|
||||
.filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class))
|
||||
.map((x) -> ((CommandInteractionMethod)x).getCommandDefinition())
|
||||
.toList();
|
||||
|
||||
execDefs.forEach((def) -> {
|
||||
Optional<ApplicationCommandDefinition> appDef = defs.stream()
|
||||
Optional<SlashCommandDefinition> appDef = defs.stream()
|
||||
.filter((x) -> x.getApplicationCommand().equals(def.applicationCommand()))
|
||||
.findFirst();
|
||||
if (appDef.isPresent())
|
||||
appDef.get().addExecutableCommand(def);
|
||||
else
|
||||
defs.add(new ApplicationCommandDefinition(def.applicationCommand()).addExecutableCommand(def));
|
||||
defs.add(new SlashCommandDefinition(def.applicationCommand()).addExecutableCommand(def));
|
||||
});
|
||||
|
||||
wrapper.registerApplicationCommands(defs.toArray(new ApplicationCommandDefinition[0]));
|
||||
wrapper.registerSlashCommands(defs.toArray(new SlashCommandDefinition[0]));
|
||||
}
|
||||
|
||||
public void handle(Object context) {
|
||||
|
@ -4,8 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.tomatentum.marinara.interaction.commands.ApplicationCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.option.OptionType;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
|
||||
@ -17,7 +17,7 @@ public abstract class LibraryWrapper {
|
||||
interactionSubscriber = new ArrayList<>();
|
||||
}
|
||||
|
||||
public abstract void registerApplicationCommands(ApplicationCommandDefinition[] defs);
|
||||
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
||||
|
||||
public void handleInteraction(Object context) {
|
||||
interactionSubscriber.forEach((o) -> o.accept(context));
|
||||
@ -32,5 +32,5 @@ public abstract class LibraryWrapper {
|
||||
|
||||
public abstract InteractionType getInteractionType(Class<?> clazz);
|
||||
public abstract Object convertCommandOption(Object context, OptionType type, String optionName);
|
||||
public abstract ExecutableCommandDefinition getCommandDefinition(Object context);
|
||||
public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user