mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-02 07:44:25 +00:00
[AB-55] fixing custom command not considering feature flag
ignoring case for custom command
This commit is contained in:
@@ -5,11 +5,14 @@ import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureConfig;
|
||||
import dev.sheldan.abstracto.customcommand.model.command.CustomCommandResponseModel;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -35,9 +38,15 @@ public class CustomCommandAlternative implements CommandAlternative {
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandFeatureConfig customCommandFeatureConfig;
|
||||
|
||||
@Override
|
||||
public boolean matches(UnParsedCommandParameter parameter) {
|
||||
return true;
|
||||
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild) {
|
||||
return featureFlagService.isFeatureEnabled(customCommandFeatureConfig, guild.getIdLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,5 +9,5 @@ import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CustomCommandRepository extends JpaRepository<CustomCommand, Long> {
|
||||
Optional<CustomCommand> getByNameAndServer(String name, AServer server);
|
||||
Optional<CustomCommand> getByNameIgnoreCaseAndServer(String name, AServer server);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ public class CustomCommandManagementServiceBean implements CustomCommandManageme
|
||||
@Override
|
||||
public Optional<CustomCommand> getCustomCommandByName(String name, Long serverId) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return repository.getByNameAndServer(name, server);
|
||||
return repository.getByNameIgnoreCaseAndServer(name, server);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
if(commandAlternatives != null) {
|
||||
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
|
||||
.stream()
|
||||
.filter(commandAlternative -> commandAlternative.matches(result.getParameter()))
|
||||
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild()))
|
||||
.findFirst();
|
||||
if(foundAlternativeOptional.isPresent()) {
|
||||
CommandAlternative foundAlternative = foundAlternativeOptional.get();
|
||||
|
||||
@@ -2,9 +2,10 @@ package dev.sheldan.abstracto.core.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.Prioritized;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
public interface CommandAlternative extends Prioritized {
|
||||
boolean matches(UnParsedCommandParameter parameter);
|
||||
boolean shouldExecute(UnParsedCommandParameter parameterm, Guild guild);
|
||||
void execute(UnParsedCommandParameter parameter, Message message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user