rename to make more sense

This commit is contained in:
tueem 2024-10-26 00:43:05 +02:00
parent fd749b31d8
commit 11ebb3fdea
No known key found for this signature in database
GPG Key ID: 819A0F7C36B9CF07
5 changed files with 30 additions and 30 deletions

@ -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.CommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
public record ExecutableCommandDefinition( public record ExecutableSlashCommandDefinition(
ApplicationCommand applicationCommand, ApplicationCommand applicationCommand,
SubCommand subCommand, SubCommand subCommand,
String[] subCommandGroups, String[] subCommandGroups,
@ -12,9 +12,9 @@ public record ExecutableCommandDefinition(
@Override @Override
public final boolean equals(Object o) { public final boolean equals(Object o) {
if (!(o instanceof ExecutableCommandDefinition)) if (!(o instanceof ExecutableSlashCommandDefinition))
return false; return false;
ExecutableCommandDefinition other = (ExecutableCommandDefinition) o; ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o;
return other.applicationCommand.name().equals(this.applicationCommand.name()) && return other.applicationCommand.name().equals(this.applicationCommand.name()) &&
other.subCommandGroups.equals(this.subCommandGroups) && other.subCommandGroups.equals(this.subCommandGroups) &&
other.subCommand.equals(this.subCommand); other.subCommand.equals(this.subCommand);
@ -38,11 +38,11 @@ public record ExecutableCommandDefinition(
this.subCommandGroupNames = new String[0]; this.subCommandGroupNames = new String[0];
} }
public ExecutableCommandDefinition build() { public ExecutableSlashCommandDefinition build() {
if (applicationCommand == null) if (applicationCommand == null)
throw new IllegalArgumentException("applicationCommandName cant be 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) { public void setApplicationCommand(ApplicationCommand applicationCommand) {

@ -6,18 +6,18 @@ import java.util.List;
import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand; import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand;
public class ApplicationCommandDefinition { public class SlashCommandDefinition {
private List<ExecutableCommandDefinition> executableDefinitons; private List<ExecutableSlashCommandDefinition> executableDefinitons;
private ApplicationCommand applicationCommand; private ApplicationCommand applicationCommand;
private int subCommandGroupCount = -1; private int subCommandGroupCount = -1;
private boolean isRootCommand = false; private boolean isRootCommand = false;
public ApplicationCommandDefinition(ApplicationCommand applicationCommand) { public SlashCommandDefinition(ApplicationCommand applicationCommand) {
this.executableDefinitons = new ArrayList<>(); this.executableDefinitons = new ArrayList<>();
this.applicationCommand = applicationCommand; this.applicationCommand = applicationCommand;
} }
public ApplicationCommandDefinition addExecutableCommand(ExecutableCommandDefinition def) { public SlashCommandDefinition addExecutableCommand(ExecutableSlashCommandDefinition def) {
if (this.subCommandGroupCount == -1) if (this.subCommandGroupCount == -1)
this.subCommandGroupCount = def.subCommandGroups().length; this.subCommandGroupCount = def.subCommandGroups().length;
if (def.subCommandGroups().length != subCommandGroupCount) if (def.subCommandGroups().length != subCommandGroupCount)
@ -46,14 +46,14 @@ public class ApplicationCommandDefinition {
return applicationCommand; return applicationCommand;
} }
public ExecutableCommandDefinition[] getExecutableDefinitons() { public ExecutableSlashCommandDefinition[] getExecutableDefinitons() {
return executableDefinitons.toArray(new ExecutableCommandDefinition[0]); return executableDefinitons.toArray(new ExecutableSlashCommandDefinition[0]);
} }
public ExecutableCommandDefinition[] getUniqueExecutableDefinitions() { public ExecutableSlashCommandDefinition[] getUniqueExecutableDefinitions() {
HashSet<ExecutableCommandDefinition> set = new HashSet<>(); HashSet<ExecutableSlashCommandDefinition> set = new HashSet<>();
executableDefinitons.forEach(set::add); executableDefinitons.forEach(set::add);
return set.toArray(new ExecutableCommandDefinition[0]); return set.toArray(new ExecutableSlashCommandDefinition[0]);
} }
public int getSubCommandGroupCount() { public int getSubCommandGroupCount() {
return subCommandGroupCount; return subCommandGroupCount;

@ -4,7 +4,7 @@ import java.lang.reflect.Method;
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.commands.ExecutableCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand; import net.tomatentum.marinara.interaction.commands.annotation.ApplicationCommand;
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;
@ -13,7 +13,7 @@ import net.tomatentum.marinara.wrapper.LibraryWrapper;
public class CommandInteractionMethod extends InteractionMethod { public class CommandInteractionMethod extends InteractionMethod {
private ExecutableCommandDefinition commandDefinition; private ExecutableSlashCommandDefinition commandDefinition;
CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) { CommandInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
super(method, handler, wrapper); super(method, handler, wrapper);
@ -27,7 +27,7 @@ public class CommandInteractionMethod extends InteractionMethod {
@Override @Override
public boolean canRun(Object context) { public boolean canRun(Object context) {
ExecutableCommandDefinition other = wrapper.getCommandDefinition(context); ExecutableSlashCommandDefinition other = wrapper.getCommandDefinition(context);
return commandDefinition.equals(other); return commandDefinition.equals(other);
} }
@ -36,7 +36,7 @@ public class CommandInteractionMethod extends InteractionMethod {
return InteractionType.COMMAND; return InteractionType.COMMAND;
} }
public ExecutableCommandDefinition getCommandDefinition() { public ExecutableSlashCommandDefinition getCommandDefinition() {
return commandDefinition; return commandDefinition;
} }
@ -44,7 +44,7 @@ public class CommandInteractionMethod extends InteractionMethod {
ReflectionUtil.checkValidCommandMethod(method); ReflectionUtil.checkValidCommandMethod(method);
ApplicationCommand cmd = ReflectionUtil.getAnnotation(method, ApplicationCommand.class); ApplicationCommand cmd = ReflectionUtil.getAnnotation(method, ApplicationCommand.class);
ExecutableCommandDefinition.Builder builder = new ExecutableCommandDefinition.Builder(); ExecutableSlashCommandDefinition.Builder builder = new ExecutableSlashCommandDefinition.Builder();
builder.setApplicationCommand(cmd); builder.setApplicationCommand(cmd);
if (ReflectionUtil.isAnnotationPresent(method, SubCommandGroup.class)) { 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.InteractionHandler;
import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.ApplicationCommandDefinition; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.methods.CommandInteractionMethod; import net.tomatentum.marinara.interaction.methods.CommandInteractionMethod;
import net.tomatentum.marinara.interaction.methods.InteractionMethod; import net.tomatentum.marinara.interaction.methods.InteractionMethod;
import net.tomatentum.marinara.wrapper.LibraryWrapper; import net.tomatentum.marinara.wrapper.LibraryWrapper;
@ -29,23 +29,23 @@ public class InteractionRegistry {
} }
public void registerCommands() { public void registerCommands() {
List<ApplicationCommandDefinition> defs = new ArrayList<>(); List<SlashCommandDefinition> defs = new ArrayList<>();
List<ExecutableCommandDefinition> execDefs = interactionMethods.stream() List<ExecutableSlashCommandDefinition> execDefs = interactionMethods.stream()
.filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class)) .filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class))
.map((x) -> ((CommandInteractionMethod)x).getCommandDefinition()) .map((x) -> ((CommandInteractionMethod)x).getCommandDefinition())
.toList(); .toList();
execDefs.forEach((def) -> { execDefs.forEach((def) -> {
Optional<ApplicationCommandDefinition> appDef = defs.stream() Optional<SlashCommandDefinition> appDef = defs.stream()
.filter((x) -> x.getApplicationCommand().equals(def.applicationCommand())) .filter((x) -> x.getApplicationCommand().equals(def.applicationCommand()))
.findFirst(); .findFirst();
if (appDef.isPresent()) if (appDef.isPresent())
appDef.get().addExecutableCommand(def); appDef.get().addExecutableCommand(def);
else 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) { public void handle(Object context) {

@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import net.tomatentum.marinara.interaction.commands.ApplicationCommandDefinition; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.option.OptionType; import net.tomatentum.marinara.interaction.commands.option.OptionType;
import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.InteractionType;
@ -17,7 +17,7 @@ public abstract class LibraryWrapper {
interactionSubscriber = new ArrayList<>(); interactionSubscriber = new ArrayList<>();
} }
public abstract void registerApplicationCommands(ApplicationCommandDefinition[] defs); public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
public void handleInteraction(Object context) { public void handleInteraction(Object context) {
interactionSubscriber.forEach((o) -> o.accept(context)); interactionSubscriber.forEach((o) -> o.accept(context));
@ -32,5 +32,5 @@ public abstract class LibraryWrapper {
public abstract InteractionType getInteractionType(Class<?> clazz); public abstract InteractionType getInteractionType(Class<?> clazz);
public abstract Object convertCommandOption(Object context, OptionType type, String optionName); public abstract Object convertCommandOption(Object context, OptionType type, String optionName);
public abstract ExecutableCommandDefinition getCommandDefinition(Object context); public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
} }