added current values to post post target

added support for custom setup steps for each feature
added mod mail category setup step
This commit is contained in:
Sheldan
2020-05-25 23:11:44 +02:00
parent 3714fd2582
commit 213f42ffbd
36 changed files with 342 additions and 24 deletions

View File

@@ -1,42 +0,0 @@
package dev.sheldan.abstracto.core.interactive;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Message;
import org.springframework.beans.factory.annotation.Autowired;
@Getter
@Setter
public abstract class AbstractConfigSetupStep implements SetupStep {
@Autowired
private InteractiveService interactiveService;
@Autowired
private TemplateService templateService;
@Autowired
private ChannelService channelService;
protected SetupExecution nextStep;
@Autowired
private InteractiveUtils interactiveUtils;
protected Runnable getTimeoutRunnable(Long serverId, Long channelId) {
return () -> {
interactiveUtils.sendTimeoutMessage(serverId, channelId);
};
}
protected boolean checkForExit(Message message) {
return message.getContentRaw().trim().equalsIgnoreCase("exit");
}
protected boolean checkForKeep(Message message) {
return message.getContentRaw().trim().equalsIgnoreCase("default");
}
}

View File

@@ -1,29 +0,0 @@
package dev.sheldan.abstracto.core.interactive;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import net.dv8tion.jda.api.entities.TextChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
@Component
public class InteractiveUtils {
@Autowired
private TemplateService templateService;
@Autowired
private ChannelService channelService;
@Transactional
public void sendTimeoutMessage(Long serverId, Long channelId) {
String s = templateService.renderSimpleTemplate("setup_configuration_timeout");
Optional<TextChannel> channelOptional = channelService.getTextChannelInGuild(serverId, channelId);
channelOptional.ifPresent(channel -> {
channelService.sendTextToChannelNoFuture(s, channel);
});
}
}

View File

@@ -4,8 +4,12 @@ import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.database.PostTarget;
import dev.sheldan.abstracto.core.models.template.commands.SetupPostTargetMessageModel;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
@@ -43,11 +47,29 @@ public class PostTargetSetupStep extends AbstractConfigSetupStep {
@Autowired
private TemplateService templateService;
@Autowired
private BotService botService;
@Autowired
private PostTargetManagement postTargetManagement;
@Override
public CompletableFuture<SetupStepResult> execute(AServerChannelUserId user, SetupStepParameter parameter) {
PostTargetStepParameter systemConfigStepParameter = (PostTargetStepParameter) parameter;
String messageTemplateKey = "setup_posttarget_" + systemConfigStepParameter.getPostTargetKey();
String messageText = templateService.renderSimpleTemplate(messageTemplateKey);
PostTargetStepParameter postTargetStepParameter = (PostTargetStepParameter) parameter;
TextChannel currentTextChannel;
if(postTargetManagement.postTargetExists(postTargetStepParameter.getPostTargetKey(), user.getGuildId())) {
PostTarget postTarget = postTargetManagement.getPostTarget(postTargetStepParameter.getPostTargetKey(), user.getGuildId());
currentTextChannel = botService.getTextChannelFromServer(user.getGuildId(), postTarget.getChannelReference().getId()).orElse(null);
} else {
currentTextChannel = null;
}
SetupPostTargetMessageModel model = SetupPostTargetMessageModel
.builder()
.postTargetKey(postTargetStepParameter.getPostTargetKey())
.currentTextChannel(currentTextChannel)
.build();
String messageTemplateKey = "setup_post_target_message";
String messageText = templateService.renderTemplate(messageTemplateKey, model);
Optional<AChannel> channel = channelManagementService.loadChannel(user.getChannelId());
CompletableFuture<SetupStepResult> future = new CompletableFuture<>();
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(user.getGuildId(), user.getUserId());
@@ -63,11 +85,12 @@ public class PostTargetSetupStep extends AbstractConfigSetupStep {
} else {
if(message.getMentionedChannels().size() == 0) {
future.completeExceptionally(new RuntimeException());
return;
}
TextChannel textChannel = message.getMentionedChannels().get(0);
PostTargetDelayedActionConfig build = PostTargetDelayedActionConfig
.builder()
.postTargetKey(systemConfigStepParameter.getPostTargetKey())
.postTargetKey(postTargetStepParameter.getPostTargetKey())
.serverId(user.getGuildId())
.textChannel(textChannel)
.channelId(textChannel.getIdLong())

View File

@@ -62,6 +62,14 @@ public class SetupServiceBean implements SetupService {
.build();
steps.add(execution);
});
featureConfig.getCustomSetupSteps().forEach(setupStep -> {
SetupExecution execution = SetupExecution
.builder()
.step(setupStep)
.parameter(EmptySetupParameter.builder().build())
.build();
steps.add(execution);
});
for (int i = 0; i < steps.size(); i++) {
SetupExecution setupExecution = steps.get(i);
setupExecution.getParameter().setPreviousMessageId(initialMessageId);

View File

@@ -0,0 +1 @@
<#assign currentTarget><#if currentTextChannel?has_content>${currentTextChannel.asMention}<#else><#include "setup_post_target_no_channel_set"></#if></#assign><#include "setup_posttarget_${postTargetKey}">