added mechanism to dynamically load properties defining postTargets and valid emoteNames

changed the output of the exception message
refactored emote management service
added service to define whether or not an emote is usable by the bot
This commit is contained in:
Sheldan
2020-03-22 10:26:58 +01:00
parent 9e9eb615c0
commit d95382b589
25 changed files with 246 additions and 100 deletions

View File

@@ -0,0 +1,10 @@
package dev.sheldan.abstracto.utility.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath:utility.properties")
public class UtilityConfig {
}

View File

@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.utility.service;
import dev.sheldan.abstracto.core.management.EmoteManagementService;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.database.PostTarget;
import dev.sheldan.abstracto.core.service.Bot;
import dev.sheldan.abstracto.core.service.MessageService;
import dev.sheldan.abstracto.core.service.PostTargetService;
@@ -24,8 +23,9 @@ import org.springframework.stereotype.Component;
public class SuggestionServiceBean implements SuggestionService {
public static final String SUGGESTION_LOG_TEMPLATE = "suggest_log";
public static final String SUGGESTION_YES_EMOTE = "SUGGESTION_YES";
public static final String SUGGESTION_NO_EMOTE = "SUGGESTION_NO";
private static final String SUGGESTION_YES_EMOTE = "SUGGESTION_YES";
private static final String SUGGESTION_NO_EMOTE = "SUGGESTION_NO";
public static final String SUGGESTIONS_TARGET = "suggestions";
@Autowired
private SuggestionManagementService suggestionManagementService;
@@ -57,7 +57,7 @@ public class SuggestionServiceBean implements SuggestionService {
JDA instance = botService.getInstance();
Guild guildById = instance.getGuildById(guildId);
if(guildById != null) {
postTargetService.sendEmbedInPostTarget(embed, PostTarget.SUGGESTIONS, guildId).thenAccept(message -> {
postTargetService.sendEmbedInPostTarget(embed, SUGGESTIONS_TARGET, guildId).thenAccept(message -> {
messageService.addReactionToMessage(SUGGESTION_YES_EMOTE, guildId, message);
messageService.addReactionToMessage(SUGGESTION_NO_EMOTE, guildId, message);
suggestionManagementService.setPostedMessage(suggestion, message);

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.utility.service.management;
import dev.sheldan.abstracto.core.models.database.PostTarget;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.templating.TemplateService;
import dev.sheldan.abstracto.utility.models.template.SuggestionLog;
@@ -15,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
import static dev.sheldan.abstracto.utility.service.SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE;
import static dev.sheldan.abstracto.utility.service.SuggestionServiceBean.SUGGESTIONS_TARGET;
@Component
@Slf4j
@@ -34,7 +34,7 @@ public class AsyncSuggestionServiceBean {
suggestionLog.setReason(text);
suggestionLog.setText(suggestionEmbed.getDescription());
MessageEmbed embed = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog);
postTargetService.sendEmbedInPostTarget(embed, PostTarget.SUGGESTIONS, suggestionLog.getServer().getId());
postTargetService.sendEmbedInPostTarget(embed, SUGGESTIONS_TARGET, suggestionLog.getServer().getId());
}
}

View File

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

View File

@@ -0,0 +1,2 @@
abstracto.postTargets.utility=suggestions
abstracto.emoteNames.suggestion=SUGGESTION_YES,SUGGESTION_NO