mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-03 08:19:54 +00:00
[AB-xxx] changing custom command auto complete to be a contains with ignored case
adding auto complete to delete custom commands
This commit is contained in:
@@ -11,12 +11,20 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandAutoCompleteService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import java.util.ArrayList;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -39,9 +47,21 @@ public class DeleteCustomCommand extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private CustomCommandService customCommandService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandManagementService customCommandManagementService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandAutoCompleteService slashCommandAutoCompleteService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private UserManagementService userManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
|
||||
@@ -54,12 +74,32 @@ public class DeleteCustomCommand extends AbstractConditionableCommand {
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> performAutoComplete(CommandAutoCompleteInteractionEvent event) {
|
||||
if(slashCommandAutoCompleteService.matchesParameter(event.getFocusedOption(), CUSTOM_COMMAND_NAME_PARAMETER)) {
|
||||
String input = event.getFocusedOption().getValue();
|
||||
if(ContextUtils.isUserCommand(event)) {
|
||||
AUser user = userManagementService.loadUser(event.getUser().getIdLong());
|
||||
return customCommandManagementService.getUserCustomCommandsContaining(input, user)
|
||||
.stream().map(customCommand -> customCommand.getName().toLowerCase())
|
||||
.toList();
|
||||
} else {
|
||||
AServer server = serverManagementService.loadServer(event.getGuild());
|
||||
return customCommandManagementService.getCustomCommandsContaining(input, server)
|
||||
.stream().map(customCommand -> customCommand.getName().toLowerCase())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter commandNameParameter = Parameter
|
||||
.builder()
|
||||
.name(CUSTOM_COMMAND_NAME_PARAMETER)
|
||||
.templated(true)
|
||||
.supportsAutoComplete(true)
|
||||
.type(String.class)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ public class GetCustomCommand extends AbstractConditionableCommand {
|
||||
if(slashCommandAutoCompleteService.matchesParameter(event.getFocusedOption(), CUSTOM_COMMAND_NAME_PARAMETER)) {
|
||||
String input = event.getFocusedOption().getValue();
|
||||
if(ContextUtils.isNotUserCommand(event)) {
|
||||
return customCommandService.getCustomCommandsStartingWith(input, event.getGuild())
|
||||
return customCommandService.getCustomCommandsContaining(input, event.getGuild())
|
||||
.stream()
|
||||
.map(CustomCommand::getName)
|
||||
.toList();
|
||||
} else {
|
||||
return customCommandService.getUserCustomCommandsStartingWith(input, event.getUser())
|
||||
return customCommandService.getUserCustomCommandsContaining(input, event.getUser())
|
||||
.stream()
|
||||
.map(CustomCommand::getName)
|
||||
.toList();
|
||||
|
||||
@@ -20,4 +20,6 @@ public interface CustomCommandRepository extends JpaRepository<CustomCommand, Lo
|
||||
List<CustomCommand> findByCreatorUserAndUserSpecific(AUser user, Boolean userSpecific);
|
||||
List<CustomCommand> findByNameStartsWithIgnoreCaseAndServer(String prefix, AServer server);
|
||||
List<CustomCommand> findByNameStartsWithIgnoreCaseAndCreatorUserAndUserSpecific(String prefix, AUser aUser, Boolean userSpecific);
|
||||
List<CustomCommand> findByNameContainingIgnoreCaseAndServer(String name, AServer server);
|
||||
List<CustomCommand> findByNameContainingIgnoreCaseAndCreatorUserAndUserSpecific(String name, AUser user, Boolean userSpecific);
|
||||
}
|
||||
|
||||
@@ -95,14 +95,14 @@ public class CustomCommandServiceBean implements CustomCommandService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild) {
|
||||
public List<CustomCommand> getCustomCommandsContaining(String name, Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild);
|
||||
return customCommandManagementService.getCustomCommandsStartingWith(prefix, server);
|
||||
return customCommandManagementService.getCustomCommandsContaining(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, User user) {
|
||||
public List<CustomCommand> getUserCustomCommandsContaining(String name, User user) {
|
||||
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
|
||||
return customCommandManagementService.getUserCustomCommandsStartingWith(prefix, aUser);
|
||||
return customCommandManagementService.getUserCustomCommandsContaining(name, aUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ public class CustomCommandManagementServiceBean implements CustomCommandManageme
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server) {
|
||||
return repository.findByNameStartsWithIgnoreCaseAndServer(prefix, server);
|
||||
public List<CustomCommand> getCustomCommandsContaining(String name, AServer server) {
|
||||
return repository.findByNameContainingIgnoreCaseAndServer(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, AUser aUser) {
|
||||
return repository.findByNameStartsWithIgnoreCaseAndCreatorUserAndUserSpecific(prefix, aUser, true);
|
||||
public List<CustomCommand> getUserCustomCommandsContaining(String prefix, AUser aUser) {
|
||||
return repository.findByNameContainingIgnoreCaseAndCreatorUserAndUserSpecific(prefix, aUser, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ public interface CustomCommandManagementService {
|
||||
void deleteCustomCommand(String name, AUser user);
|
||||
List<CustomCommand> getCustomCommands(AServer server);
|
||||
List<CustomCommand> getUserCustomCommands(AUser aUser);
|
||||
List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server);
|
||||
List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, AUser aUser);
|
||||
List<CustomCommand> getCustomCommandsContaining(String prefix, AServer server);
|
||||
List<CustomCommand> getUserCustomCommandsContaining(String prefix, AUser aUser);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@ public interface CustomCommandService {
|
||||
List<CustomCommand> getUserCustomCommands(User user);
|
||||
CustomCommand getCustomCommand(String name, Guild guild);
|
||||
CustomCommand getUserCustomCommand(String name, User user);
|
||||
List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild);
|
||||
List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, User user);
|
||||
List<CustomCommand> getCustomCommandsContaining(String name, Guild guild);
|
||||
List<CustomCommand> getUserCustomCommandsContaining(String name, User user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user