mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-13 03:26:31 +00:00
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:
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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}">
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.interactive.SetupStep;
|
||||
import dev.sheldan.abstracto.core.service.FeatureValidator;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -18,4 +19,5 @@ public interface FeatureConfig {
|
||||
default List<FeatureValidator> getAdditionalFeatureValidators() { return Collections.emptyList(); }
|
||||
default List<String> getRequiredEmotes() { return Collections.emptyList(); }
|
||||
default List<FeatureMode> getAvailableModes() { return Collections.emptyList(); };
|
||||
default List<SetupStep> getCustomSetupSteps() { return Collections.emptyList(); }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class EmptySetupParameter implements SetupStepParameter {
|
||||
private Long previousMessageId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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 SetupPostTargetMessageModel {
|
||||
private String postTargetKey;
|
||||
private TextChannel currentTextChannel;
|
||||
}
|
||||
Reference in New Issue
Block a user