mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-25 05:57:06 +00:00
reworked exception handling, different exceptions whether or why it failed, all of which are unchecked
added feature flags for commands/listeners added enable/disable command added feature flag handling to command received handler added boolean parameter support fixed 1 parameter commands fixed posttargets not working on multiple servers, removed unique constraint on posttarget names added setup validation to suggestions added quartz property loader moved join/leave logger to moderation reworked the way the message listener are handled (separate listener around)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public abstract class AbstractFeatureFlaggedCommand implements ConditionalCommand {
|
||||
|
||||
@Autowired
|
||||
private FeatureEnabledCondition featureEnabledCondition;
|
||||
|
||||
@Override
|
||||
public List<CommandCondition> getConditions() {
|
||||
return Arrays.asList(featureEnabledCondition);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,11 @@ package dev.sheldan.abstracto.command;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAware;
|
||||
|
||||
public interface Command<T> {
|
||||
public interface Command extends FeatureAware {
|
||||
|
||||
Result execute(CommandContext commandContext);
|
||||
CommandResult execute(CommandContext commandContext);
|
||||
CommandConfiguration getConfiguration();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandContext;
|
||||
|
||||
public interface CommandCondition {
|
||||
boolean shouldExecute(CommandContext commandContext, Command command);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ConditionalCommand extends Command {
|
||||
List<CommandCondition> getConditions();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.service.management.FeatureFlagManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FeatureEnabledCondition implements CommandCondition {
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagManagementService featureFlagManagementService;
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute(CommandContext context, Command command) {
|
||||
String featureName = command.getFeature();
|
||||
if(featureName != null) {
|
||||
return featureFlagManagementService.getFeatureFlagValue(featureName, context.getGuild().getIdLong());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.command.execution.CommandResult;
|
||||
|
||||
public interface PostCommandExecution {
|
||||
void execute(CommandContext commandContext, Result result, Command command);
|
||||
void execute(CommandContext commandContext, CommandResult commandResult, Command command);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
public interface TemplatedException {
|
||||
public interface Templatable {
|
||||
String getTemplateName();
|
||||
Object getTemplateModel();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
public class CommandResult {
|
||||
private ResultState result;
|
||||
private String message;
|
||||
private Throwable throwable;
|
||||
|
||||
public static CommandResult fromSuccess() {
|
||||
return CommandResult.builder().result(ResultState.SUCCESSFUL).build();
|
||||
}
|
||||
|
||||
public static CommandResult fromError(String message){
|
||||
return CommandResult.builder().result(ResultState.ERROR).message(message).build();
|
||||
}
|
||||
|
||||
public static CommandResult fromError(String message, Throwable throwable) {
|
||||
return CommandResult.builder().result(ResultState.ERROR).message(message).throwable(throwable).build();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class ContextConverter {
|
||||
return builder
|
||||
.member(commandContext.getAuthor())
|
||||
.guild(commandContext.getGuild())
|
||||
.textChannel(commandContext.getChannel())
|
||||
.messageChannel(commandContext.getChannel())
|
||||
.channel(commandContext.getUserInitiatedContext().getChannel())
|
||||
.server(commandContext.getUserInitiatedContext().getServer())
|
||||
.aUserInAServer(commandContext.getUserInitiatedContext().getAUserInAServer())
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
public class Result {
|
||||
private ResultState result;
|
||||
private String message;
|
||||
private Throwable throwable;
|
||||
|
||||
public static Result fromSuccess() {
|
||||
return Result.builder().result(ResultState.SUCCESSFUL).build();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user