Compare commits

..

No commits in common. "9d3a6b8b8501f311b6d30355d62500287e9b3792" and "432db43bf598017f54642573ea2d96010efc9060" have entirely different histories.

8 changed files with 36 additions and 271 deletions

@ -1,12 +1,5 @@
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 {
}

@ -27,8 +27,8 @@ public record ExecutableSlashCommandDefinition(
ExecutableSlashCommandDefinition other = (ExecutableSlashCommandDefinition) o;
boolean equals = false;
if (this.applicationCommand() != null && other.applicationCommand() != null)
equals = this.applicationCommand().name().equals(other.applicationCommand().name());
if (this.applicationCommand() != null && other.subCommandGroup() != null)
equals = this.applicationCommand.name().equals(other.applicationCommand().name());
if (this.subCommandGroup() != null && other.subCommandGroup() != null)
equals = this.subCommandGroup().name().equals(other.subCommandGroup().name());

@ -4,7 +4,6 @@ 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;
@ -27,8 +26,7 @@ public class JavacordContextObjectProvider implements ContextObjectProvider {
}
private Object getOptionValue(SlashCommandInteractionOption option) {
SlashCommandOptionType type = getOptionType(option);
switch (type) {
switch (getOptionType(option)) {
case ATTACHMENT:
return option.getAttachmentValue().get();
case BOOLEAN:
@ -40,40 +38,40 @@ public class JavacordContextObjectProvider implements ContextObjectProvider {
case LONG:
return option.getLongValue().get();
case MENTIONABLE:
return option.requestMentionableValue().get();
return option.getMentionableValue().get();
case ROLE:
return option.getRoleValue().get();
case STRING:
return option.getStringValue().get();
case USER:
return option.requestUserValue().get();
return option.getUserValue().get();
default:
return null;
}
}
private SlashCommandOptionType getOptionType(SlashCommandInteractionOption option) {
private org.javacord.api.interaction.SlashCommandOptionType getOptionType(SlashCommandInteractionOption option) {
if (option.getAttachmentValue().isPresent())
return SlashCommandOptionType.ATTACHMENT;
return org.javacord.api.interaction.SlashCommandOptionType.ATTACHMENT;
if (option.getBooleanValue().isPresent())
return SlashCommandOptionType.BOOLEAN;
return org.javacord.api.interaction.SlashCommandOptionType.BOOLEAN;
if (option.getChannelValue().isPresent())
return SlashCommandOptionType.CHANNEL;
return org.javacord.api.interaction.SlashCommandOptionType.CHANNEL;
if (option.getDecimalValue().isPresent())
return SlashCommandOptionType.DECIMAL;
return org.javacord.api.interaction.SlashCommandOptionType.DECIMAL;
if (option.getLongValue().isPresent())
return SlashCommandOptionType.LONG;
if (option.requestMentionableValue().isPresent())
return SlashCommandOptionType.MENTIONABLE;
return org.javacord.api.interaction.SlashCommandOptionType.LONG;
if (option.getMentionableValue().isPresent())
return org.javacord.api.interaction.SlashCommandOptionType.MENTIONABLE;
if (option.getRoleValue().isPresent())
return SlashCommandOptionType.ROLE;
return org.javacord.api.interaction.SlashCommandOptionType.ROLE;
if (option.getStringValue().isPresent())
return SlashCommandOptionType.STRING;
if (option.requestUserValue().isPresent())
return SlashCommandOptionType.USER;
return org.javacord.api.interaction.SlashCommandOptionType.ATTACHMENT;
if (option.getUserValue().isPresent())
return org.javacord.api.interaction.SlashCommandOptionType.USER;
return SlashCommandOptionType.UNKNOWN;
return org.javacord.api.interaction.SlashCommandOptionType.UNKNOWN;
}
@Override

@ -42,12 +42,13 @@ public class JavacordWrapper extends LibraryWrapper {
@Override
public InteractionType getInteractionType(Class<?> clazz) {
if (AutocompleteInteraction.class.isAssignableFrom(clazz))
return InteractionType.AUTOCOMPLETE;
if (ApplicationCommandInteraction.class.isAssignableFrom(clazz))
return InteractionType.COMMAND;
if (ButtonInteraction.class.isAssignableFrom(clazz))
return InteractionType.BUTTON;
if (AutocompleteInteraction.class.isAssignableFrom(clazz))
return InteractionType.AUTOCOMPLETE;
return null;
}
@ -82,13 +83,11 @@ public class JavacordWrapper extends LibraryWrapper {
List<SlashCommandInteractionOption> options = interaction.getOptions();
try {
builder.setApplicationCommand(TypeFactory.annotation(SlashCommand.class, Map.of("name", interaction.getCommandName())));
if (!options.isEmpty()) {
if (!options.getFirst().getArguments().isEmpty()) {
builder.setSubCommandGroup(TypeFactory.annotation(SubCommandGroup.class, Map.of("name", options.getFirst().getName())));
builder.setSubCommand(TypeFactory.annotation(SubCommand.class, Map.of("name", options.getFirst().getOptions().getFirst().getName())));
}else
builder.setSubCommand(TypeFactory.annotation(SubCommand.class, Map.of("name", options.getFirst().getName())));
}
} catch (AnnotationFormatException e) {
e.printStackTrace();
}

@ -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,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
public Optional<Long> getLongValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getLongValue'");
}
@Override
public Optional<Boolean> getBooleanValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getBooleanValue'");
}
@Override
public Optional<User> getUserValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getUserValue'");
}
@Override
public Optional<CompletableFuture<User>> requestUserValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'requestUserValue'");
}
@Override
public Optional<ServerChannel> getChannelValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getChannelValue'");
}
@Override
public Optional<Attachment> getAttachmentValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getAttachmentValue'");
}
@Override
public Optional<Role> getRoleValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getRoleValue'");
}
@Override
public Optional<Mentionable> getMentionableValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getMentionableValue'");
}
@Override
public Optional<Double> getDecimalValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'getDecimalValue'");
}
@Override
public Optional<CompletableFuture<Mentionable>> requestMentionableValue() {
return Optional.empty();
throw new UnsupportedOperationException("Unimplemented method 'requestMentionableValue'");
}
@Override