mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-13 03:26:31 +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.command.service.CommandRegistry;
|
||||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
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.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
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.command.CustomCommandResponseModel;
|
||||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -35,9 +38,15 @@ public class CustomCommandAlternative implements CommandAlternative {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TemplateService templateService;
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FeatureFlagService featureFlagService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CustomCommandFeatureConfig customCommandFeatureConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(UnParsedCommandParameter parameter) {
|
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild) {
|
||||||
return true;
|
return featureFlagService.isFeatureEnabled(customCommandFeatureConfig, guild.getIdLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ import java.util.Optional;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CustomCommandRepository extends JpaRepository<CustomCommand, Long> {
|
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
|
@Override
|
||||||
public Optional<CustomCommand> getCustomCommandByName(String name, Long serverId) {
|
public Optional<CustomCommand> getCustomCommandByName(String name, Long serverId) {
|
||||||
AServer server = serverManagementService.loadServer(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) {
|
if(commandAlternatives != null) {
|
||||||
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
|
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
|
||||||
.stream()
|
.stream()
|
||||||
.filter(commandAlternative -> commandAlternative.matches(result.getParameter()))
|
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if(foundAlternativeOptional.isPresent()) {
|
if(foundAlternativeOptional.isPresent()) {
|
||||||
CommandAlternative foundAlternative = foundAlternativeOptional.get();
|
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.Prioritized;
|
||||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
public interface CommandAlternative extends Prioritized {
|
public interface CommandAlternative extends Prioritized {
|
||||||
boolean matches(UnParsedCommandParameter parameter);
|
boolean shouldExecute(UnParsedCommandParameter parameterm, Guild guild);
|
||||||
void execute(UnParsedCommandParameter parameter, Message message);
|
void execute(UnParsedCommandParameter parameter, Message message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user