added warn and ban command

changed command context to be a member instead of user, commands are only supported within guilds
added custom exception templating for the error message
added error message in case the parameters for a command were too little
added support for templates on command help descriptions
added post execution to be executed to print exception messages
refactored command handling to be able to support exceptions
added user and userInServer management
This commit is contained in:
Sheldan
2020-03-18 18:21:06 +01:00
parent 167bbb0f8b
commit bd848d31d3
82 changed files with 913 additions and 151 deletions

View File

@@ -1,11 +1,11 @@
package dev.sheldan.abstracto.command;
import dev.sheldan.abstracto.command.execution.Configuration;
import dev.sheldan.abstracto.command.execution.CommandConfiguration;
import dev.sheldan.abstracto.command.execution.CommandContext;
import dev.sheldan.abstracto.command.execution.Result;
public interface Command<T> {
Result execute(CommandContext commandContext);
Configuration getConfiguration();
CommandConfiguration getConfiguration();
}

View File

@@ -7,4 +7,6 @@ import lombok.Getter;
public class HelpInfo {
private String usage;
private String longHelp;
private String longHelpTemplate;
private String usageTemplate;
}

View File

@@ -0,0 +1,6 @@
package dev.sheldan.abstracto.command;
public interface TemplatedException {
String getTemplateName();
Object getTemplateModel();
}

View File

@@ -8,16 +8,17 @@ import lombok.Setter;
import java.util.List;
@Getter @Builder
public class Configuration {
public class CommandConfiguration {
private String name;
private String module;
private String description;
private String descriptionTemplate;
private List<Parameter> parameters;
private boolean causesReaction;
private HelpInfo help;
public long getNecessaryParameterCount(){
return parameters.stream().filter(parameter -> !parameter.isOptional()).count();
public int getNecessaryParameterCount(){
return (int) parameters.stream().filter(parameter -> !parameter.isOptional()).count();
}
}

View File

@@ -3,17 +3,14 @@ package dev.sheldan.abstracto.command.execution;
import lombok.Builder;
import lombok.Getter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.*;
@Builder
@Getter
public class CommandContext {
private TextChannel channel;
private Guild guild;
private User author;
private Member author;
private Message message;
private CommandTemplateContext commandTemplateContext;
private Parameters parameters;

View File

@@ -9,6 +9,7 @@ import lombok.Setter;
public class Result {
private ResultState result;
private String message;
private Throwable throwable;
public static Result fromSuccess() {
return Result.builder().result(ResultState.SUCCESSFUL).build();
@@ -17,4 +18,8 @@ public class Result {
public static Result fromError(String message){
return Result.builder().result(ResultState.ERROR).message(message).build();
}
public static Result fromError(String message, Throwable throwable) {
return Result.builder().result(ResultState.ERROR).message(message).throwable(throwable).build();
}
}