added module responsible for accumulating the dependencies and resulting in a jar

added channels module
added help info object to command configuration
added description field to parameter
added modules for commands (and packed modules), they are mapped by name
added post command execution interface
added support for optional parameters
added support for using guildchannel as parameter
added printing of modules to help command
added service beans to wrap over the operations on the repository
added synchronizing of channels/roles on startup (controlled by flag)
added builder annotations to model classes
added more model classes
This commit is contained in:
Sheldan
2019-12-12 16:47:54 +01:00
parent 42cfe33b3a
commit 5c6b7b9a78
61 changed files with 1136 additions and 138 deletions

View File

@@ -0,0 +1,61 @@
package dev.sheldan.abstracto.command;
import lombok.Builder;
import lombok.Getter;
import java.util.List;
import java.util.Optional;
@Getter @Builder
public class CommandHierarchy {
private List<PackedModule> rootModules;
public PackedModule getModuleWithName(String name){
for (PackedModule module: rootModules) {
PackedModule found = getModuleWithName(name, module);
if(found != null){
return found;
}
}
return null;
}
private PackedModule getModuleWithName(String name, PackedModule module){
if(module.getModule().getInfo().getName().equals(name)){
return module;
} else {
for (PackedModule subModule: module.getSubModules()) {
PackedModule possibleModule = getModuleWithName(name, subModule);
if(possibleModule != null){
return possibleModule;
}
}
return null;
}
}
public Command getCommandWithName(String name) {
for (PackedModule module: rootModules) {
Command command = getCommandFromModule(name, module);
if(command != null){
return command;
}
}
return null;
}
private Command getCommandFromModule(String name, PackedModule module){
Command foundCommand = module.getCommands().stream().filter(command -> command.getConfiguration().getName().equals(name)).findAny().orElse(null);
if(foundCommand == null){
for (PackedModule subModule: module.getSubModules()) {
Command command = getCommandFromModule(name, subModule);
if(command != null){
return command;
}
}
return null;
} else {
return foundCommand;
}
}
}

View File

@@ -0,0 +1,10 @@
package dev.sheldan.abstracto.command;
import lombok.Builder;
import lombok.Getter;
@Getter @Builder
public class HelpInfo {
private String usage;
private String longHelp;
}

View File

@@ -0,0 +1,8 @@
package dev.sheldan.abstracto.command;
import dev.sheldan.abstracto.command.module.ModuleInfo;
public interface Module {
ModuleInfo getInfo();
String getParentModule();
}

View File

@@ -0,0 +1,9 @@
package dev.sheldan.abstracto.command;
import java.util.List;
public interface ModuleRegistry {
CommandHierarchy getDetailedModules();
List<Module> getModules();
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.command;
import lombok.Builder;
import lombok.Getter;
import java.util.List;
@Builder
@Getter
public class PackedModule {
private Module module;
private PackedModule parentModule;
private List<PackedModule> subModules;
private List<Command> commands;
}

View File

@@ -0,0 +1,8 @@
package dev.sheldan.abstracto.command;
import dev.sheldan.abstracto.command.execution.Context;
import dev.sheldan.abstracto.command.execution.Result;
public interface PostCommandExecution {
void execute(Context context, Result result, Command command);
}

View File

@@ -1,12 +1,13 @@
package dev.sheldan.abstracto.command.execution;
import dev.sheldan.abstracto.command.HelpInfo;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter @Setter @Builder
@Getter @Builder
public class Configuration {
private String name;
@@ -14,4 +15,9 @@ public class Configuration {
private String description;
private List<Parameter> parameters;
private boolean causesReaction;
private HelpInfo help;
public long getNecessaryParameterCount(){
return parameters.stream().filter(parameter -> !parameter.isOptional()).count();
}
}

View File

@@ -8,6 +8,7 @@ import lombok.Setter;
public class Parameter {
private String name;
private Class type;
private String description;
private boolean optional;
private boolean remainder;
}

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.command.meta;
import dev.sheldan.abstracto.command.Command;
import dev.sheldan.abstracto.command.Module;
import net.dv8tion.jda.api.entities.Message;
import java.util.List;
@@ -10,5 +11,6 @@ public interface CommandRegistry {
Command findCommandByParameters(String name, UnParsedCommandParameter context);
Command findCommand(String message);
List<Command> getAllCommands();
List<Command> getAllCommandsFromModule(Module module);
boolean isCommand(Message message);
}

View File

@@ -0,0 +1,17 @@
package dev.sheldan.abstracto.command.module;
import dev.sheldan.abstracto.command.Module;
import org.springframework.stereotype.Service;
@Service
public class AbstracatoModule implements Module {
@Override
public ModuleInfo getInfo() {
return ModuleInfo.builder().name("default").description("Default module provided by abstracto").build();
}
@Override
public String getParentModule() {
return null;
}
}

View File

@@ -0,0 +1,11 @@
package dev.sheldan.abstracto.command.module;
import lombok.Builder;
import lombok.Getter;
@Getter @Builder
public class ModuleInfo {
private String name;
private String description;
}