mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-30 07:06:24 +00:00
enabling auto complete for youtube command
This commit is contained in:
@@ -82,6 +82,11 @@ public class ListenerExecutorConfig {
|
||||
return executorService.setupExecutorFor("slashCommandListener");
|
||||
}
|
||||
|
||||
@Bean(name = "slashCommandAutoCompleteExecutor")
|
||||
public TaskExecutor slashCommandAutoCompleteExecutor() {
|
||||
return executorService.setupExecutorFor("slashCommandAutoCompleteListener");
|
||||
}
|
||||
|
||||
@Bean(name = "emoteDeletedExecutor")
|
||||
public TaskExecutor emoteDeletedExecutor() {
|
||||
return executorService.setupExecutorFor("emoteDeletedListener");
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -41,6 +42,10 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
@Qualifier("slashCommandExecutor")
|
||||
private TaskExecutor slashCommandExecutor;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("slashCommandAutoCompleteExecutor")
|
||||
private TaskExecutor slashCommandAutoCompleteExecutor;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandListenerBean self;
|
||||
|
||||
@@ -100,6 +105,29 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInteractionEvent event) {
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
CompletableFuture.runAsync(() -> self.executeAutCompleteListenerLogic(event), slashCommandAutoCompleteExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async auto complete interaction event.", throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void executeAutCompleteListenerLogic(CommandAutoCompleteInteractionEvent event) {
|
||||
Optional<Command> potentialCommand = findCommand(event);
|
||||
potentialCommand.ifPresent(command -> {
|
||||
try {
|
||||
List<String> replies = command.performAutoComplete(event);
|
||||
event.replyChoiceStrings(replies).queue(unused -> {},
|
||||
throwable -> log.error("Failed to response to complete of command {} in guild {}.", command.getConfiguration().getName(), event.getGuild().getIdLong()));
|
||||
} catch (Exception exception) {
|
||||
log.error("Error while executing autocomplete of command {}.", command.getConfiguration().getName(), exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = AbstractoRunTimeException.class)
|
||||
public void executeCommand(SlashCommandInteractionEvent event, Command command, ConditionResult conditionResult) {
|
||||
CompletableFuture<CommandResult> commandOutput;
|
||||
@@ -136,6 +164,14 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
.findAny();
|
||||
}
|
||||
|
||||
private Optional<Command> findCommand(CommandAutoCompleteInteractionEvent event) {
|
||||
return commands
|
||||
.stream()
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().isEnabled())
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().matchesInteraction(event.getInteraction()))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void filterPostProcessors() {
|
||||
metricService.registerCounter(SLASH_COMMANDS_PROCESSED_COUNTER, "Slash Commands processed");
|
||||
|
||||
@@ -124,11 +124,7 @@ public class SlashCommandServiceBean implements SlashCommandService {
|
||||
optionalParameters.add(new OptionData(type, parameter.getSlashCompatibleName() + "_" + i, parameterDescription, false));
|
||||
}
|
||||
} else {
|
||||
if(!parameter.isOptional()) {
|
||||
requiredParameters.add(new OptionData(type, parameter.getSlashCompatibleName(), parameterDescription, true));
|
||||
} else {
|
||||
optionalParameters.add(new OptionData(type, parameter.getSlashCompatibleName(), parameterDescription, false));
|
||||
}
|
||||
requiredParameters.add(new OptionData(type, parameter.getSlashCompatibleName(), parameterDescription, !parameter.isOptional(), parameter.getSupportsAutoComplete()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.interaction.slash.parameter;
|
||||
|
||||
import net.dv8tion.jda.api.interactions.AutoCompleteQuery;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SlashCommandAutoCompleteServiceBean implements SlashCommandAutoCompleteService{
|
||||
@Override
|
||||
public boolean matchesParameter(AutoCompleteQuery query, String parameterName) {
|
||||
return query.getName().equalsIgnoreCase(parameterName);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,16 @@
|
||||
<heap unit="entries">2000</heap>
|
||||
</resources>
|
||||
</cache>
|
||||
<!-- TODO no nice way yet to have this configuration split up -->
|
||||
<cache uses-template="default" alias="general-use-cache">
|
||||
<expiry>
|
||||
<ttl unit="seconds">7200</ttl>
|
||||
</expiry>
|
||||
|
||||
<resources>
|
||||
<heap unit="entries">2000</heap>
|
||||
</resources>
|
||||
</cache>
|
||||
<cache-template name="default">
|
||||
<expiry>
|
||||
<ttl unit="seconds">600</ttl>
|
||||
|
||||
Reference in New Issue
Block a user