[AB-218] adding ability to split the normal message as well according to custom configuration

adding ability to define the max amount of messages resulting from a template on a server and template base
fixing not always considering the server when rendering templates in various places
This commit is contained in:
Sheldan
2021-03-30 20:29:13 +02:00
parent 33959d696a
commit 6375dbf463
28 changed files with 213 additions and 83 deletions

View File

@@ -77,7 +77,7 @@ public class SuggestionServiceBean implements SuggestionService {
suggestionLog.setState(SuggestionState.NEW);
suggestionLog.setSuggesterUser(suggester);
suggestionLog.setText(text);
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog);
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog, member.getGuild().getIdLong());
long guildId = member.getGuild().getIdLong();
log.info("Creating suggestion with id {} in server {} from member {}.", newSuggestionId, member.getGuild().getId(), member.getId());
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SuggestionPostTarget.SUGGESTION, guildId);
@@ -144,7 +144,7 @@ public class SuggestionServiceBean implements SuggestionService {
MessageEmbed suggestionEmbed = embedOptional.get();
suggestionLog.setReason(text);
suggestionLog.setText(suggestionEmbed.getDescription());
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog);
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog, suggestionLog.getGuild().getIdLong());
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SuggestionPostTarget.SUGGESTION, suggestionLog.getGuild().getIdLong());
return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0]));
} else {

View File

@@ -106,10 +106,9 @@ public class SuggestionServiceBeanTest {
SuggestionLog log = Mockito.mock(SuggestionLog.class);
when(suggestionCreator.getGuild()).thenReturn(guild);
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(serverManagementService.loadServer(suggestionCreator.getGuild())).thenReturn(server);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
when(templateService.renderEmbedTemplate(eq(SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE), any(SuggestionLog.class))).thenReturn(messageToSend);
when(templateService.renderEmbedTemplate(eq(SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE), any(SuggestionLog.class), eq(SERVER_ID))).thenReturn(messageToSend);
Message suggestionMessage = Mockito.mock(Message.class);
when(counterService.getNextCounterValue(server, SuggestionServiceBean.SUGGESTION_COUNTER_KEY)).thenReturn(SUGGESTION_ID);
AUserInAServer aUserInAServer = Mockito.mock(AUserInAServer.class);
@@ -193,7 +192,7 @@ public class SuggestionServiceBeanTest {
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(suggestionMessage.getEmbeds()).thenReturn(Arrays.asList(embed));
MessageToSend updatedMessage = Mockito.mock(MessageToSend.class);
when(templateService.renderEmbedTemplate(eq(SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE), any(SuggestionLog.class))).thenReturn(updatedMessage);
when(templateService.renderEmbedTemplate(eq(SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE), any(SuggestionLog.class), eq(SERVER_ID))).thenReturn(updatedMessage);
testUnit.updateSuggestionMessageText(CLOSING_TEXT, log, suggestionMessage);
verify(postTargetService, times(1)).sendEmbedInPostTarget(updatedMessage, SuggestionPostTarget.SUGGESTION, SERVER_ID);
}