refactor(autocomplete): implement autocompleteRefs and remove SlashCommand annotation on Autocomplete Method
This commit is contained in:
@@ -1,38 +1,53 @@
|
||||
package net.tomatentum.marinara.wrapper.discord4j.identifierconverter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||
import net.tomatentum.marinara.registry.InteractionEntry;
|
||||
import net.tomatentum.marinara.registry.InteractionRegistry;
|
||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
|
||||
public class AutocompleteIdentifierConverter implements IdentifierProvider.Converter<ChatInputAutoCompleteEvent> {
|
||||
|
||||
@Override
|
||||
public InteractionIdentifier convert(ChatInputAutoCompleteEvent context) {
|
||||
public InteractionIdentifier convert(ChatInputAutoCompleteEvent context, InteractionRegistry registry) {
|
||||
List<ApplicationCommandInteractionOption> options = Discord4JWrapper.SUB_FILTER.apply(context.getOptions());
|
||||
String commandName = context.getCommandName();
|
||||
InteractionIdentifier ident;
|
||||
|
||||
if (!options.isEmpty()) {
|
||||
List<ApplicationCommandInteractionOption> sub_options = Discord4JWrapper.SUB_FILTER.apply(options.getFirst().getOptions());
|
||||
if (!sub_options.isEmpty())
|
||||
return InteractionIdentifier.createHierarchy(
|
||||
InteractionType.AUTOCOMPLETE,
|
||||
ident = InteractionIdentifier.createHierarchy(
|
||||
InteractionType.COMMAND,
|
||||
commandName,
|
||||
options.getFirst().getName(),
|
||||
sub_options.getFirst().getName());
|
||||
else
|
||||
return InteractionIdentifier.createHierarchy(
|
||||
InteractionType.AUTOCOMPLETE,
|
||||
ident = InteractionIdentifier.createHierarchy(
|
||||
InteractionType.COMMAND,
|
||||
commandName,
|
||||
options.getFirst().getName());
|
||||
}else
|
||||
return InteractionIdentifier.createHierarchy(
|
||||
InteractionType.AUTOCOMPLETE,
|
||||
ident = InteractionIdentifier.createHierarchy(
|
||||
InteractionType.COMMAND,
|
||||
commandName);
|
||||
|
||||
Optional<InteractionEntry> entry = registry.findFor(ident);
|
||||
if (entry.isPresent() && entry.get().identifier() instanceof SlashCommandIdentifier) {
|
||||
SlashCommandIdentifier sIdent = (SlashCommandIdentifier) entry.get().identifier();
|
||||
return InteractionIdentifier.builder()
|
||||
.type(InteractionType.AUTOCOMPLETE)
|
||||
.name(sIdent.autocompleteRef()[0])
|
||||
.build();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,12 +3,13 @@ package net.tomatentum.marinara.wrapper.discord4j.identifierconverter;
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.registry.InteractionRegistry;
|
||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||
|
||||
public class ButtonIdentifierConverter implements IdentifierProvider.Converter<ButtonInteractionEvent> {
|
||||
|
||||
@Override
|
||||
public InteractionIdentifier convert(ButtonInteractionEvent context) {
|
||||
public InteractionIdentifier convert(ButtonInteractionEvent context, InteractionRegistry registry) {
|
||||
return InteractionIdentifier.builder().name(context.getCustomId()).type(InteractionType.BUTTON).build();
|
||||
}
|
||||
|
||||
|
@@ -6,13 +6,14 @@ import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.registry.InteractionRegistry;
|
||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
|
||||
public class SlashCommandIdentifierConverter implements IdentifierProvider.Converter<ChatInputInteractionEvent> {
|
||||
|
||||
@Override
|
||||
public InteractionIdentifier convert(ChatInputInteractionEvent context) {
|
||||
public InteractionIdentifier convert(ChatInputInteractionEvent context, InteractionRegistry registry) {
|
||||
List<ApplicationCommandInteractionOption> options = Discord4JWrapper.SUB_FILTER.apply(context.getOptions());
|
||||
String commandName = context.getCommandName();
|
||||
|
||||
|
@@ -5,14 +5,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.Collections;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
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
|
||||
@AutoComplete("testAuto")
|
||||
public void exec(ChatInputInteractionEvent context) {
|
||||
|
||||
}
|
||||
|
||||
@AutoComplete("testAuto")
|
||||
public void autocomplete(ChatInputAutoCompleteEvent context, String value) {
|
||||
System.out.println("Success!");
|
||||
assertEquals(value, "test");
|
||||
|
Reference in New Issue
Block a user