added dynamic post target loading

fixed some templates of commands
added fat jar maven config
This commit is contained in:
Sheldan
2020-03-21 18:39:46 +01:00
parent f416ac5d6b
commit 9e9eb615c0
13 changed files with 62 additions and 5 deletions

View File

@@ -0,0 +1 @@
abstracto.postTargets.moderation=joinLog,leaveLog,warnLog,kickLog,banLog,editLog,deleteLog

View File

@@ -0,0 +1 @@
abstracto.postTargets.utility=suggestions

View File

@@ -0,0 +1 @@
Accepts the given suggestion. Will post the suggestion again, with the given reason for acceptance, with the old text strike through and 'Accepted by' as a notice.

View File

@@ -0,0 +1 @@
Rejects the given suggestion. Will post the suggestion again, with the given reason for rejection, with the old text strike through and 'Rejected by' as a notice.

View File

@@ -0,0 +1,31 @@
package dev.sheldan.abstracto.core;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@Component
@Getter
@Setter
@PropertySource("classpath:abstracto.properties")
@ConfigurationProperties(prefix = "abstracto")
public class PostTargetLoader {
private HashMap<String, String> postTargets = new HashMap<>();
public List<String> getPostTargetsAsList() {
List<String> targets = new ArrayList<>();
if(postTargets == null || postTargets.size() == 0) {
return targets;
}
postTargets.values().forEach(s -> targets.addAll(Arrays.asList(s.split(","))));
return targets;
}
}

View File

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
@Service
public class Ping implements Command {
public static final String PING_TEMPLATE = "ping";
public static final String PING_TEMPLATE = "ping_response";
@Autowired
private TemplateService templateService;

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.PostTargetLoader;
import dev.sheldan.abstracto.core.exception.PostTargetException;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
@@ -25,9 +26,12 @@ public class PostTargetManagementBean implements PostTargetManagement {
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private PostTargetLoader postTargetLoader;
@Override
public void createPostTarget(String name, AServer server, AChannel targetChannel) {
if(!PostTarget.AVAILABLE_POST_TARGETS.contains(name)) {
if(!postTargetLoader.getPostTargetsAsList().contains(name)) {
throw new PostTargetException("PostTarget not found");
}
log.info("Creating post target {} pointing towards {}", name, targetChannel);

View File

@@ -8,7 +8,7 @@ import java.util.concurrent.CompletableFuture;
public interface PostTargetService {
CompletableFuture<Message> sendTextInPostTarget(String text, PostTarget target);
CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTarget target);
CompletableFuture<Message> sendTextInPostTarget(String text, String postTargetName, Long serverId);
CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, String postTargetName, Long serverId);
CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTarget target);
CompletableFuture<Message> sendTextInPostTarget(String text, String postTargetName, Long serverId);
CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, String postTargetName, Long serverId);
}

View File

@@ -8,9 +8,23 @@
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>executable</artifactId>
<properties>
<start-class>dev.sheldan.abstracto.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>