[AB-76] replaced usage templates for commands with a generated usage string, removed possibility to define the usage directly on the help

added Google guava dependency
minor fixes in documentation
fixed versions in main pom
This commit is contained in:
Sheldan
2020-09-24 02:40:44 +02:00
parent 76adda90a3
commit 5081c3174f
14 changed files with 358 additions and 14 deletions

View File

@@ -1,9 +1,11 @@
package dev.sheldan.abstracto.core.command.service;
import com.google.common.collect.Iterables;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
import dev.sheldan.abstracto.core.command.condition.ConditionalCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.database.ACommand;
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
@@ -27,6 +29,8 @@ import java.util.List;
public class CommandServiceBean implements CommandService {
public static final String NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE = "no_feature_command_found_exception";
private static final String[] MANDATORY_ENCLOSING = {"<", ">"};
private static final String[] OPTIONAL_ENCLOSING = {"[", "]"};
@Autowired
private ModuleManagementService moduleManagementService;
@@ -91,6 +95,26 @@ public class CommandServiceBean implements CommandService {
commandForServer.setRestricted(true);
}
@Override
public String generateUsage(Command command) {
StringBuilder builder = new StringBuilder();
CommandConfiguration commandConfig = command.getConfiguration();
builder.append(commandConfig.getName());
if(!commandConfig.getParameters().isEmpty()) {
builder.append(" ");
}
commandConfig.getParameters().forEach(parameter -> {
String[] enclosing = parameter.isOptional() ? OPTIONAL_ENCLOSING : MANDATORY_ENCLOSING;
builder.append(enclosing[0]);
builder.append(parameter.getName());
builder.append(enclosing[1]);
if(!parameter.equals(Iterables.getLast(commandConfig.getParameters()))) {
builder.append(" ");
}
});
return builder.toString();
}
@Override
public void unRestrictCommand(ACommand aCommand, AServer server) {
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, server);

View File

@@ -94,6 +94,7 @@ public class Help implements Command {
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);
channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel());