mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-13 19:41:38 +00:00
[AB-215] adding create alias and delete alias commands to create service specific aliases for commands
renaming package in commands package defaulting to latest in docker compose build for deployment container fixing jacoco configuration changing that if there are no parameters required, parameters are accepted
This commit is contained in:
@@ -113,7 +113,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
||||
UnParsedCommandParameter unParsedParameter = new UnParsedCommandParameter(contentStripped, event.getMessage());
|
||||
String commandName = commandManager.getCommandName(parameters.get(0), event.getGuild().getIdLong());
|
||||
foundCommand = commandManager.findCommandByParameters(commandName, unParsedParameter);
|
||||
foundCommand = commandManager.findCommandByParameters(commandName, unParsedParameter, event.getGuild().getIdLong());
|
||||
tryToExecuteFoundCommand(event, foundCommand, unParsedParameter);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
@@ -39,7 +39,7 @@ public class CommandConfigListenerAsync implements AsyncServerCreatedListener {
|
||||
if(command.getConfiguration() != null) {
|
||||
ACommand aCommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
||||
if(!commandInServerManagementService.doesCommandExistInServer(aCommand, server)) {
|
||||
commandInServerManagementService.crateCommandInServer(aCommand, server);
|
||||
commandInServerManagementService.createCommandInServer(aCommand, server);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.command.config.features.CoreFeatureConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
import dev.sheldan.abstracto.core.command.models.condition.GenericConditionModel;
|
||||
import dev.sheldan.abstracto.core.command.model.condition.GenericConditionModel;
|
||||
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
|
||||
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.core.command.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||
import dev.sheldan.abstracto.core.command.model.database.CommandInServerAliasId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CommandInServerAliasRepository extends JpaRepository<ACommandInServerAlias, CommandInServerAliasId> {
|
||||
List<ACommandInServerAlias> findByCommandInAServer_ServerReference(AServer server);
|
||||
Optional<ACommandInServerAlias> findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(AServer server, String name);
|
||||
List<ACommandInServerAlias> findByCommandInAServer_ServerReferenceAndCommandInAServer_CommandReference_NameEqualsIgnoreCase(AServer server, String name);
|
||||
boolean existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(AServer server, String name);
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package dev.sheldan.abstracto.core.command.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface CommandInServerRepository extends JpaRepository<ACommandInAServer, Long> {
|
||||
|
||||
ACommandInAServer findByServerReferenceAndCommandReference(AServer server, ACommand command);
|
||||
Optional<ACommandInAServer> findByServerReferenceAndCommandReference(AServer server, ACommand command);
|
||||
|
||||
ACommandInAServer findByServerReference_IdAndCommandReference(Long serverId, ACommand command);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandAliasAlreadyExistsException;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandAliasDoesNotExistsException;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandAliasHidesCommandException;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerAliasManagementServiceBean;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class CommandInServerAliasServiceBean implements CommandInServerAliasService {
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasManagementServiceBean commandInServerAliasManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private CommandInServerService commandInServerService;
|
||||
|
||||
@Autowired
|
||||
private CommandRegistry commandRegistry;
|
||||
|
||||
@Override
|
||||
public ACommandInServerAlias createAliasForCommandInServer(Long serverId, String commandName, String alias) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
Optional<ACommandInServerAlias> existingAlias = commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, alias);
|
||||
if(existingAlias.isPresent()) {
|
||||
throw new CommandAliasAlreadyExistsException(existingAlias.get().getCommandInAServer().getCommandReference().getName());
|
||||
}
|
||||
Optional<Command> existingCommand = commandRegistry.getCommandByNameOptional(alias, false, serverId);
|
||||
if(existingCommand.isPresent()) {
|
||||
throw new CommandAliasHidesCommandException(existingCommand.get().getConfiguration().getName());
|
||||
}
|
||||
ACommandInAServer aCommandInAServer = commandInServerService.getCommandInAServer(server, commandName);
|
||||
return commandInServerAliasManagementServiceBean.createAliasForCommand(aCommandInAServer, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ACommandInServerAlias> getCommandInServerAlias(Long serverId, String text) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCommandInServerAlias(Long serverId, String name) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
Optional<ACommandInServerAlias> existingAlias = commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, name);
|
||||
if(existingAlias.isPresent()) {
|
||||
commandInServerAliasManagementServiceBean.deleteCommandInServerAlias(existingAlias.get());
|
||||
} else {
|
||||
throw new CommandAliasDoesNotExistsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliasesForCommand(Long serverId, String commandName) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return commandInServerAliasManagementServiceBean.getAliasesForCommandInServer(server, commandName)
|
||||
.stream().map(alias -> alias.getAliasId().getName())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CommandInServerServiceBean implements CommandInServerService {
|
||||
|
||||
@Autowired
|
||||
private CommandManagementService commandManagementService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private CommandInServerManagementService commandInServerManagementService;
|
||||
|
||||
@Override
|
||||
public ACommandInAServer getCommandInAServer(Long serverId, String name) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return getCommandInAServer(server, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ACommandInAServer getCommandInAServer(AServer server, String name) {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
return commandInServerManagementService.getCommandForServer(command, server);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import dev.sheldan.abstracto.core.command.config.ModuleDefinition;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -17,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Service
|
||||
public class CommandManager implements CommandRegistry {
|
||||
@@ -34,52 +38,90 @@ public class CommandManager implements CommandRegistry {
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasService commandInServerAliasService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
||||
if(commandConfiguration == null) {
|
||||
return false;
|
||||
}
|
||||
if(!commandNameMatches(name, commandConfiguration)) {
|
||||
return false;
|
||||
}
|
||||
boolean parameterFit;
|
||||
if(commandConfiguration.getParameters() != null){
|
||||
if(commandConfiguration.getNecessaryParameterCount() > unParsedCommandParameter.getParameters().size()) {
|
||||
String nextParameterName = commandConfiguration.getParameters().get(commandConfiguration.getNecessaryParameterCount() - 1).getName();
|
||||
metricService.incrementCounter(CommandReceivedHandler.COMMANDS_WRONG_PARAMETER_COUNTER);
|
||||
throw new InsufficientParametersException(o, nextParameterName);
|
||||
}
|
||||
parameterFit = true;
|
||||
} else {
|
||||
parameterFit = unParsedCommandParameter.getParameters().isEmpty();
|
||||
}
|
||||
return parameterFit;
|
||||
}).findFirst();
|
||||
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter, Long serverId) {
|
||||
Optional<Command> commandOptional = commands.stream().filter(getCommandByNameAndParameterPredicate(name, unParsedCommandParameter)).findFirst();
|
||||
if(!commandOptional.isPresent()) {
|
||||
commandOptional = getCommandViaAliasAndParameter(name, unParsedCommandParameter, serverId);
|
||||
}
|
||||
if(commandOptional.isPresent()){
|
||||
return commandOptional.get();
|
||||
}
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
private boolean commandNameMatches(String name, CommandConfiguration commandConfiguration) {
|
||||
boolean commandNameMatches = commandConfiguration.getName().equalsIgnoreCase(name);
|
||||
if(commandNameMatches) {
|
||||
return true;
|
||||
private Optional<Command> getCommandViaAliasAndParameter(String name, UnParsedCommandParameter unParsedCommandParameter, Long serverId) {
|
||||
Optional<ACommandInServerAlias> aliasOptional = commandInServerAliasService.getCommandInServerAlias(serverId, name);
|
||||
if(aliasOptional.isPresent()) {
|
||||
// if its present, retrieve the original command
|
||||
ACommandInAServer command = aliasOptional.get().getCommandInAServer();
|
||||
// and find the command based on the newly found name
|
||||
return commands.stream().filter(getCommandByNameAndParameterPredicate(command.getCommandReference().getName(), unParsedCommandParameter)).findFirst();
|
||||
}
|
||||
boolean aliasesMatch = false;
|
||||
if(commandConfiguration.getAliases() != null) {
|
||||
aliasesMatch = commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
||||
}
|
||||
return aliasesMatch;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Command findCommand(String name) {
|
||||
private Optional<Command> getCommandViaAlias(String name, Long serverId) {
|
||||
Optional<ACommandInServerAlias> aliasOptional = commandInServerAliasService.getCommandInServerAlias(serverId, name);
|
||||
if(aliasOptional.isPresent()) {
|
||||
// if its present, retrieve the original command
|
||||
ACommandInAServer command = aliasOptional.get().getCommandInAServer();
|
||||
// and find the command based on the newly found name
|
||||
return commands.stream().filter(getCommandByNamePredicate(command.getCommandReference().getName())).findFirst();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Predicate<Command> getCommandByNameAndParameterPredicate(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
||||
return (Command commandObj) -> {
|
||||
CommandConfiguration commandConfiguration = commandObj.getConfiguration();
|
||||
if (commandConfiguration == null) {
|
||||
return false;
|
||||
}
|
||||
if (!commandNameOrAliasMatches(name, commandConfiguration)) {
|
||||
return false;
|
||||
}
|
||||
return verifyCommandConfiguration(unParsedCommandParameter, commandObj, commandConfiguration);
|
||||
};
|
||||
}
|
||||
|
||||
private Predicate<Command> getCommandByNamePredicate(String name) {
|
||||
return (Command commandObj) -> {
|
||||
CommandConfiguration commandConfiguration = commandObj.getConfiguration();
|
||||
if (commandConfiguration == null) {
|
||||
return false;
|
||||
}
|
||||
return commandNameOrAliasMatches(name, commandConfiguration);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean verifyCommandConfiguration(UnParsedCommandParameter unParsedCommandParameter, Command command, CommandConfiguration commandConfiguration) {
|
||||
if(commandConfiguration.getParameters() != null && commandConfiguration.getNecessaryParameterCount() > unParsedCommandParameter.getParameters().size()){
|
||||
String nextParameterName = commandConfiguration.getParameters().get(commandConfiguration.getNecessaryParameterCount() - 1).getName();
|
||||
metricService.incrementCounter(CommandReceivedHandler.COMMANDS_WRONG_PARAMETER_COUNTER);
|
||||
throw new InsufficientParametersException(command, nextParameterName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean commandNameOrAliasMatches(String name, CommandConfiguration commandConfiguration) {
|
||||
return commandConfiguration.getName().equalsIgnoreCase(name) ||
|
||||
commandConfiguration.getAliases() != null && commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command findCommandViaName(String name) {
|
||||
return commands.stream().filter((Command o )-> {
|
||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
||||
return commandConfiguration.getName().equals(name);
|
||||
}).findFirst().orElseThrow(CommandNotFoundException::new);
|
||||
return commandConfiguration.getName().equalsIgnoreCase(name);
|
||||
}).findFirst()
|
||||
.orElseThrow(CommandNotFoundException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,22 +143,50 @@ public class CommandManager implements CommandRegistry {
|
||||
|
||||
@Override
|
||||
public boolean isCommand(Message message) {
|
||||
return message.getContentRaw().startsWith(configService.getStringValue(PREFIX, message.getGuild().getIdLong(), getDefaultPrefix()));
|
||||
return message.getContentRaw().startsWith(getPrefix(message.getGuild().getIdLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commandExists(String name) {
|
||||
return commands.stream().anyMatch(command -> command.getConfiguration().getName().equalsIgnoreCase(name));
|
||||
public boolean commandExists(String name, boolean searchAliases, Long serverId) {
|
||||
boolean defaultCommands = commands.stream().anyMatch(findCommandViaCommandConfig(name));
|
||||
if(defaultCommands) {
|
||||
return true;
|
||||
}
|
||||
if(searchAliases) {
|
||||
return commandInServerAliasService.getCommandInServerAlias(serverId, name).isPresent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Predicate<Command> findCommandViaCommandConfig(String name) {
|
||||
return command -> command.getConfiguration().getName().equalsIgnoreCase(name) || command.getConfiguration().getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command getCommandByName(String name) {
|
||||
return commands.stream().filter(command -> command.getConfiguration().getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
public Command getCommandByName(String name, boolean searchAliases, Long serverId) {
|
||||
Optional<Command> defaultCommand = commands.stream().filter(findCommandViaCommandConfig(name)).findFirst();
|
||||
if(defaultCommand.isPresent()) {
|
||||
return defaultCommand.get();
|
||||
} else {
|
||||
if(searchAliases) {
|
||||
return getCommandViaAlias(name, serverId).orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Command> getCommandByNameOptional(String name, boolean searchAliases, Long serverId) {
|
||||
return Optional.ofNullable(getCommandByName(name, searchAliases, serverId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName(String input, Long serverId) {
|
||||
return input.replaceFirst(configService.getStringValue(PREFIX, serverId, getDefaultPrefix()), "");
|
||||
return input.replaceFirst(getPrefix(serverId), "");
|
||||
}
|
||||
|
||||
private String getPrefix(Long serverId) {
|
||||
return configService.getStringValue(PREFIX, serverId, getDefaultPrefix());
|
||||
}
|
||||
|
||||
private String getDefaultPrefix() {
|
||||
|
||||
@@ -10,9 +10,9 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
@@ -175,7 +175,7 @@ public class CommandServiceBean implements CommandService {
|
||||
public CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent) {
|
||||
String contentStripped = messageContainingContent.getContentRaw();
|
||||
UnParsedCommandParameter unParsedParameter = getUnParsedCommandParameter(contentStripped, messageContainingContent);
|
||||
Command command = commandRegistry.findCommandByParameters(commandName, unParsedParameter);
|
||||
Command command = commandRegistry.findCommandByParameters(commandName, unParsedParameter, messageContainingContent.getGuild().getIdLong());
|
||||
return commandReceivedHandler.getParsedParameters(unParsedParameter, command, messageContainingContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.core.command.service;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.exception.GenericExceptionModel;
|
||||
import dev.sheldan.abstracto.core.command.model.exception.GenericExceptionModel;
|
||||
import dev.sheldan.abstracto.core.models.FullUser;
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.repository.ChannelGroupCommandRepository;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package dev.sheldan.abstracto.core.command.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||
import dev.sheldan.abstracto.core.command.model.database.CommandInServerAliasId;
|
||||
import dev.sheldan.abstracto.core.command.repository.CommandInServerAliasRepository;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class CommandInServerAliasManagementServiceBean implements CommandInServerAliasManagementService {
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasRepository repository;
|
||||
|
||||
@Override
|
||||
public List<ACommandInServerAlias> getAliasesInServer(AServer server) {
|
||||
return repository.findByCommandInAServer_ServerReference(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesCommandInServerAliasExist(AServer server, String alias) {
|
||||
return repository.existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ACommandInServerAlias> getCommandInServerAlias(AServer server, String alias) {
|
||||
return repository.findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ACommandInServerAlias createAliasForCommand(ACommandInAServer commandInAServer, String aliasName) {
|
||||
CommandInServerAliasId identifier = CommandInServerAliasId
|
||||
.builder()
|
||||
.commandInServerId(commandInAServer.getCommandInServerId())
|
||||
.name(aliasName)
|
||||
.build();
|
||||
ACommandInServerAlias alias = ACommandInServerAlias
|
||||
.builder()
|
||||
.commandInAServer(commandInAServer)
|
||||
.aliasId(identifier)
|
||||
.build();
|
||||
return repository.save(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCommandInServerAlias(ACommandInServerAlias alias) {
|
||||
repository.delete(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ACommandInServerAlias> getAliasesForCommandInServer(AServer server, String commandName) {
|
||||
return repository.findByCommandInAServer_ServerReferenceAndCommandInAServer_CommandReference_NameEqualsIgnoreCase(server, commandName);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.command.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.repository.CommandInServerRepository;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -17,7 +18,7 @@ public class CommandInServerManagementServiceBean implements CommandInServerMana
|
||||
|
||||
|
||||
@Override
|
||||
public ACommandInAServer crateCommandInServer(ACommand command, AServer server) {
|
||||
public ACommandInAServer createCommandInServer(ACommand command, AServer server) {
|
||||
ACommandInAServer commandInAServer = ACommandInAServer
|
||||
.builder()
|
||||
.commandReference(command)
|
||||
@@ -30,12 +31,12 @@ public class CommandInServerManagementServiceBean implements CommandInServerMana
|
||||
|
||||
@Override
|
||||
public boolean doesCommandExistInServer(ACommand command, AServer server) {
|
||||
return getCommandForServer(command, server) != null;
|
||||
return repository.findByServerReferenceAndCommandReference(server, command).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ACommandInAServer getCommandForServer(ACommand command, AServer server) {
|
||||
return repository.findByServerReferenceAndCommandReference(server, command);
|
||||
return repository.findByServerReferenceAndCommandReference(server, command).orElseThrow(CommandNotFoundException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.command.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.repository.CommandRepository;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@@ -58,4 +59,9 @@ public class CommandManagementServiceBean implements CommandManagementService {
|
||||
return commandRepository.existsByNameIgnoreCase(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ACommand> getAllCommands() {
|
||||
return commandRepository.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||
import dev.sheldan.abstracto.core.command.repository.ModuleRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package dev.sheldan.abstracto.core.commands.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CreateAlias extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasService aliasService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String commandName = (String) parameters.get(0);
|
||||
String aliasName = (String) parameters.get(1);
|
||||
aliasService.createAliasForCommandInServer(commandContext.getGuild().getIdLong(), commandName, aliasName);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter commandNameParameter = Parameter.builder().name("commandName").type(String.class).templated(true).build();
|
||||
Parameter aliasParameter = Parameter.builder().name("alias").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(commandNameParameter, aliasParameter);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("createAlias")
|
||||
.module(ConfigModuleDefinition.CONFIG)
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.sheldan.abstracto.core.commands.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DeleteAlias extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasService aliasService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String aliasName = (String) parameters.get(0);
|
||||
aliasService.deleteCommandInServerAlias(commandContext.getGuild().getIdLong(), aliasName);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter aliasParameter = Parameter.builder().name("alias").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(aliasParameter);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("deleteAlias")
|
||||
.module(ConfigModuleDefinition.CONFIG)
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
|
||||
@@ -6,8 +6,9 @@ import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
|
||||
@@ -30,10 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@@ -69,6 +67,9 @@ public class Help implements Command {
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
@Autowired
|
||||
private CommandInServerAliasService commandInServerAliasService;
|
||||
|
||||
public static final String HELP_COMMAND_EXECUTED_METRIC = "help.executions";
|
||||
public static final String CATEGORY = "category";
|
||||
private static final CounterMetric HELP_COMMAND_NO_PARAMETER_METRIC =
|
||||
@@ -127,26 +128,31 @@ public class Help implements Command {
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_module_details_response", model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||
} else if(commandRegistry.commandExists(parameter)) {
|
||||
metricService.incrementCounter(HELP_COMMAND_COMMAND_METRIC);
|
||||
Command command = commandRegistry.getCommandByName(parameter);
|
||||
log.trace("Displaying help for command {}.", command.getConfiguration().getName());
|
||||
ACommand aCommand = commandManagementService.findCommandByName(parameter);
|
||||
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getGuild().getIdLong());
|
||||
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
|
||||
if(Boolean.TRUE.equals(aCommandInAServer.getRestricted())) {
|
||||
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
|
||||
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
|
||||
model.setRestricted(true);
|
||||
}
|
||||
model.setUsage(commandService.generateUsage(command));
|
||||
model.setCommand(command.getConfiguration());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_command_details_response", model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||
} else {
|
||||
metricService.incrementCounter(HELP_COMMAND_WRONG_PARAM_METRIC);
|
||||
return displayHelpOverview(commandContext);
|
||||
Optional<Command> commandOptional = commandRegistry.getCommandByNameOptional(parameter, true, commandContext.getGuild().getIdLong());
|
||||
if(commandOptional.isPresent()) {
|
||||
metricService.incrementCounter(HELP_COMMAND_COMMAND_METRIC);
|
||||
Command command = commandOptional.get();
|
||||
log.trace("Displaying help for command {}.", command.getConfiguration().getName());
|
||||
ACommand aCommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
||||
List<String> aliases = commandInServerAliasService.getAliasesForCommand(commandContext.getGuild().getIdLong(), command.getConfiguration().getName());
|
||||
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getGuild().getIdLong());
|
||||
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
|
||||
model.setServerSpecificAliases(aliases);
|
||||
if(Boolean.TRUE.equals(aCommandInAServer.getRestricted())) {
|
||||
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
|
||||
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
|
||||
model.setRestricted(true);
|
||||
}
|
||||
model.setUsage(commandService.generateUsage(command));
|
||||
model.setCommand(command.getConfiguration());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_command_details_response", model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||
} else {
|
||||
metricService.incrementCounter(HELP_COMMAND_WRONG_PARAM_METRIC);
|
||||
return displayHelpOverview(commandContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.exception.ChannelGroupNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
||||
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||
import dev.sheldan.abstracto.core.repository.LockRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
@@ -43,6 +46,11 @@ public class StartupServiceBean implements Startup {
|
||||
@Autowired
|
||||
private RoleManagementService roleManagementService;
|
||||
|
||||
@Autowired
|
||||
private CommandManagementService commandManagementService;
|
||||
|
||||
@Autowired
|
||||
private CommandInServerManagementService commandInServerManagementService;
|
||||
|
||||
@Override
|
||||
public void startBot() throws LoginException {
|
||||
@@ -62,6 +70,7 @@ public class StartupServiceBean implements Startup {
|
||||
JDA instance = service.getInstance();
|
||||
List<Guild> onlineGuilds = instance.getGuilds();
|
||||
Set<Long> availableServers = SnowflakeUtils.getSnowflakeIds(onlineGuilds);
|
||||
List<ACommand> existingCommands = commandManagementService.getAllCommands();
|
||||
availableServers.forEach(aLong -> {
|
||||
AServer newAServer = serverManagementService.loadOrCreate(aLong);
|
||||
Guild newGuild = instance.getGuildById(aLong);
|
||||
@@ -69,11 +78,20 @@ public class StartupServiceBean implements Startup {
|
||||
if(newGuild != null){
|
||||
synchronizeRolesOf(newGuild, newAServer);
|
||||
synchronizeChannelsOf(newGuild, newAServer);
|
||||
synchronizeCommandsInServer(newAServer, existingCommands);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void synchronizeCommandsInServer(AServer newAServer, List<ACommand> commands) {
|
||||
commands.forEach(aCommand -> {
|
||||
if(!commandInServerManagementService.doesCommandExistInServer(aCommand, newAServer)) {
|
||||
commandInServerManagementService.createCommandInServer(aCommand, newAServer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void synchronizeRolesOf(Guild guild, AServer existingAServer){
|
||||
List<Role> guildRoles = guild.getRoles();
|
||||
List<ARole> existingRoles = existingAServer.getRoles();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
||||
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
||||
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||
import dev.sheldan.abstracto.core.exception.UserInServerNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
||||
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.core.repository.UserRepository;
|
||||
import dev.sheldan.abstracto.core.service.LockService;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
|
||||
<include file="core-tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
<include file="core-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<property name="coreFeature" value="(SELECT id FROM feature WHERE key = 'core')"/>
|
||||
<property name="configModule" value="(SELECT id FROM module WHERE name = 'config')"/>
|
||||
<changeSet author="Sheldan" id="createAlias-command" >
|
||||
<insert tableName="command">
|
||||
<column name="name" value="createAlias"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="deleteAlias"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="command_in_server_alias-table">
|
||||
<createTable tableName="command_in_server_alias">
|
||||
<column name="command_in_server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addPrimaryKey columnNames="command_in_server_id, name" tableName="command_in_server_alias" constraintName="pk_command_in_server_alias" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="command_in_server_id" baseTableName="command_in_server_alias" constraintName="fk_command_in_server_alias_command_in_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="command_in_server_id" referencedTableName="command_in_server" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS command_in_server_alias_insert_trigger ON command_in_server_alias;
|
||||
CREATE TRIGGER command_in_server_alias_insert_trigger BEFORE INSERT ON command_in_server_alias FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<include file="command_in_server_alias.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -10,4 +10,5 @@
|
||||
<include file="1.0-templating/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.1-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.2.5-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user