added setup command which includes an interactive process in order to setup features

the current supported features are post targets and system config
the wizard includes a summary step where the user can confirm the changes
removed some unnecessary validators, which were basically just validating the system config from some features
fixed post target name
This commit is contained in:
Sheldan
2020-05-22 17:25:44 +02:00
parent e2f71ef7a3
commit 992357b2cb
81 changed files with 1074 additions and 92 deletions

View File

@@ -0,0 +1,19 @@
package dev.sheldan.abstracto.core.exception;
import dev.sheldan.abstracto.templating.Templatable;
public class SetupStepException extends AbstractoRunTimeException implements Templatable {
public SetupStepException(String message) {
super(message);
}
@Override
public String getTemplateName() {
return "setup_configuration_timeout";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,7 @@
package dev.sheldan.abstracto.core.interactive;
public interface DelayedAction {
void execute(DelayedActionConfig delayedActionConfig);
boolean handles(DelayedActionConfig delayedActionConfig);
}

View File

@@ -0,0 +1,6 @@
package dev.sheldan.abstracto.core.interactive;
import dev.sheldan.abstracto.templating.Templatable;
public interface DelayedActionConfig extends Templatable {
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.interactive;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.util.function.Consumer;
public interface InteractiveService {
void createMessageWithResponse(String templateKey, AUserInAServer responder, AChannel channel, Long messageId, Consumer<MessageReceivedEvent> action, Runnable finalAction);
void createMessageWithResponse(MessageToSend messageToSend, AUserInAServer responder, AChannel channel, Long messageId, Consumer<MessageReceivedEvent> action, Runnable finalAction);
void createMessageWithConfirmation(String text, AUserInAServer responder, AChannel channel, Long messageId, Consumer<Void> confirmation, Consumer<Void> denial, Runnable finalAction);
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.interactive;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class SetupExecution {
private SetupStep step;
private SetupStepParameter parameter;
private SetupExecution nextStep;
}

View File

@@ -0,0 +1,11 @@
package dev.sheldan.abstracto.core.interactive;
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface SetupStep {
CompletableFuture<List<DelayedActionConfig>> execute(AServerChannelUserId aUserInAServer, SetupStepParameter parameter);
}

View File

@@ -0,0 +1,6 @@
package dev.sheldan.abstracto.core.interactive;
public interface SetupStepParameter {
Long getPreviousMessageId();
void setPreviousMessageId(Long previousMessageId);
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.models;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class AServerChannelUserId {
private Long guildId;
private Long channelId;
private Long userId;
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.core.models.template.commands;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.TextChannel;
@Getter
@Setter
@Builder
public class PostTargetActionModel {
private String postTargetKey;
private Long channelId;
private TextChannel channel;
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models.template.commands;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class SetupCompletedNotificationModel {
private FeatureConfig completedFeature;
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.core.models.template.commands;
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
@Builder
public class SetupSummaryModel {
private List<DelayedActionConfig> actionConfigs;
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models.template.commands;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class SystemConfigActionModel {
private String configKey;
private Object newValue;
}

View File

@@ -28,7 +28,7 @@ public interface ChannelService {
void editMessageInAChannel(MessageToSend messageToSend, MessageChannel channel, Long messageId);
CompletableFuture<Void> deleteTextChannel(AChannel channel);
CompletableFuture<Void> deleteTextChannel(Long serverId, Long channelId);
List<CompletableFuture<Message>> sendTemplateInChannel(String templateKey, Object model, MessageChannel channel);
List<CompletableFuture<Message>> sendEmbedTemplateInChannel(String templateKey, Object model, MessageChannel channel);
CompletableFuture<TextChannel> createTextChannel(String name, AServer server, Long categoryId);
}

View File

@@ -10,5 +10,7 @@ public interface ConfigService {
void setLongValue(String name, Long serverId, Long value);
void setConfigValue(String name, Long serverId, String value);
void setStringValue(String name, Long serverId, String value);
boolean configIsFitting(String name, Long serverId, String value);
void validateConfig(String name, Long serverId, String value);
}

View File

@@ -0,0 +1,9 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
import java.util.List;
public interface DelayedActionService {
void executeDelayedActions(List<DelayedActionConfig> delayedActionConfigList);
}

View File

@@ -7,10 +7,13 @@ import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface MessageService {
void addReactionToMessage(String emoteKey, Long serverId, Message message);
CompletableFuture<Void> addReactionToMessageWithFuture(String emoteKey, Long serverId, Message message);
List<CompletableFuture<Void>> addReactionsToMessageWithFuture(List<String> emoteKeys, Long serverId, Message message);
CompletableFuture<Void> deleteMessageInChannelInServer(Long serverId, Long channelId, Long messageId);
CompletableFuture<Message> createStatusMessage(MessageToSend messageToSend, AChannel channel);
void updateStatusMessage(AChannel channel, Long messageId, MessageToSend messageToSend);

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.interactive.SetupExecution;
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
import java.util.List;
public interface SetupService {
void performSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId);
void executeSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs);
}