mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-25 20:04:01 +00:00
[AB-234] allow templates have individual (additional) allowed mention configurations
adding primary keys to command disabled and command cooldown group exposing service method to retrieve the channel for a post target
This commit is contained in:
@@ -10,10 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -37,7 +34,7 @@ public class AllowedMentionServiceBean implements AllowedMentionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Message.MentionType> getAllowedMentionTypesForServer(Long serverId) {
|
public Set<Message.MentionType> getAllowedMentionTypesForServer(Long serverId) {
|
||||||
AllowedMention allowedMention = getEffectiveAllowedMention(serverId);
|
AllowedMention allowedMention = getEffectiveAllowedMention(serverId);
|
||||||
return mapAllowedMentionToMentionType(allowedMention);
|
return mapAllowedMentionToMentionType(allowedMention);
|
||||||
}
|
}
|
||||||
@@ -79,12 +76,12 @@ public class AllowedMentionServiceBean implements AllowedMentionService {
|
|||||||
throw new UnknownMentionTypeException();
|
throw new UnknownMentionTypeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Message.MentionType> mapAllowedMentionToMentionType(AllowedMention allowedMention) {
|
private Set<Message.MentionType> mapAllowedMentionToMentionType(AllowedMention allowedMention) {
|
||||||
// if all are allowed, we dont want to restrict it
|
// if all are allowed, we dont want to restrict it
|
||||||
if(allowedMention.allAllowed()) {
|
if(allowedMention.allAllowed()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Message.MentionType> types = new ArrayList<>();
|
Set<Message.MentionType> types = new HashSet<>();
|
||||||
if(allowedMention.getEveryone()) {
|
if(allowedMention.getEveryone()) {
|
||||||
types.add(Message.MentionType.EVERYONE);
|
types.add(Message.MentionType.EVERYONE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.core.metric.service.MetricService;
|
|||||||
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.templating.model.MessageConfig;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||||
import dev.sheldan.abstracto.core.utils.FileService;
|
import dev.sheldan.abstracto.core.utils.FileService;
|
||||||
@@ -22,10 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static dev.sheldan.abstracto.core.config.MetricConstants.DISCORD_API_INTERACTION_METRIC;
|
import static dev.sheldan.abstracto.core.config.MetricConstants.DISCORD_API_INTERACTION_METRIC;
|
||||||
@@ -126,21 +124,34 @@ public class ChannelServiceBean implements ChannelService {
|
|||||||
log.debug("Sending message {} from channel {} and server {} to channel {}.",
|
log.debug("Sending message {} from channel {} and server {} to channel {}.",
|
||||||
message.getId(), message.getChannel().getId(), message.getGuild().getId(), channel.getId());
|
message.getId(), message.getChannel().getId(), message.getGuild().getId(), channel.getId());
|
||||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||||
return channel.sendMessage(message).allowedMentions(getAllowedMentionsFor(channel)).submit();
|
return channel.sendMessage(message).allowedMentions(getAllowedMentionsFor(channel, null)).submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Message.MentionType> getAllowedMentionsFor(MessageChannel channel) {
|
private Set<Message.MentionType> getAllowedMentionsFor(MessageChannel channel, MessageToSend messageToSend) {
|
||||||
|
Set<Message.MentionType> allowedMentions = new HashSet<>();
|
||||||
if(channel instanceof GuildChannel) {
|
if(channel instanceof GuildChannel) {
|
||||||
return allowedMentionService.getAllowedMentionTypesForServer(((GuildChannel) channel).getGuild().getIdLong());
|
allowedMentions.addAll(allowedMentionService.getAllowedMentionTypesForServer(((GuildChannel) channel).getGuild().getIdLong()));
|
||||||
}
|
}
|
||||||
return null;
|
if(messageToSend != null && messageToSend.getMessageConfig() != null) {
|
||||||
|
MessageConfig messageConfig = messageToSend.getMessageConfig();
|
||||||
|
if(messageConfig.isAllowsEveryoneMention()) {
|
||||||
|
allowedMentions.add(Message.MentionType.EVERYONE);
|
||||||
|
}
|
||||||
|
if(messageConfig.isAllowsUserMention()) {
|
||||||
|
allowedMentions.add(Message.MentionType.USER);
|
||||||
|
}
|
||||||
|
if(messageConfig.isAllowsRoleMention()) {
|
||||||
|
allowedMentions.add(Message.MentionType.ROLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allowedMentions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Message> sendTextToChannel(String text, MessageChannel channel) {
|
public CompletableFuture<Message> sendTextToChannel(String text, MessageChannel channel) {
|
||||||
log.debug("Sending text to channel {}.", channel.getId());
|
log.debug("Sending text to channel {}.", channel.getId());
|
||||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||||
return channel.sendMessage(text).allowedMentions(getAllowedMentionsFor(channel)).submit();
|
return channel.sendMessage(text).allowedMentions(getAllowedMentionsFor(channel, null)).submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,7 +180,7 @@ public class ChannelServiceBean implements ChannelService {
|
|||||||
@Override
|
@Override
|
||||||
public MessageAction sendEmbedToChannelInComplete(MessageEmbed embed, MessageChannel channel) {
|
public MessageAction sendEmbedToChannelInComplete(MessageEmbed embed, MessageChannel channel) {
|
||||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||||
return channel.sendMessage(embed).allowedMentions(getAllowedMentionsFor(channel));
|
return channel.sendMessage(embed).allowedMentions(getAllowedMentionsFor(channel, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -232,7 +243,7 @@ public class ChannelServiceBean implements ChannelService {
|
|||||||
allMessageActions.add(textChannel.sendFile(messageToSend.getFileToSend()));
|
allMessageActions.add(textChannel.sendFile(messageToSend.getFileToSend()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Message.MentionType> allowedMentions = getAllowedMentionsFor(textChannel);
|
Set<Message.MentionType> allowedMentions = getAllowedMentionsFor(textChannel, messageToSend);
|
||||||
allMessageActions.forEach(messageAction ->
|
allMessageActions.forEach(messageAction ->
|
||||||
futures.add(messageAction.allowedMentions(allowedMentions).submit())
|
futures.add(messageAction.allowedMentions(allowedMentions).submit())
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ public class PostTargetServiceBean implements PostTargetService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PostTarget getPostTarget(PostTargetEnum postTargetName, Long serverId) {
|
@Override
|
||||||
|
public PostTarget getPostTarget(PostTargetEnum postTargetName, Long serverId) {
|
||||||
PostTarget postTarget = postTargetManagement.getPostTarget(postTargetName.getKey(), serverId);
|
PostTarget postTarget = postTargetManagement.getPostTarget(postTargetName.getKey(), serverId);
|
||||||
if(postTarget != null) {
|
if(postTarget != null) {
|
||||||
return postTarget;
|
return postTarget;
|
||||||
|
|||||||
@@ -55,8 +55,5 @@ public class EmbedConfiguration {
|
|||||||
* The message which is posted along the {@link net.dv8tion.jda.api.entities.MessageEmbed} as a normal message.
|
* The message which is posted along the {@link net.dv8tion.jda.api.entities.MessageEmbed} as a normal message.
|
||||||
*/
|
*/
|
||||||
private String additionalMessage;
|
private String additionalMessage;
|
||||||
private Long additionalMessageLengthLimit;
|
private MetaEmbedConfiguration metaConfig;
|
||||||
private Long messageLimit;
|
|
||||||
|
|
||||||
private boolean preventEmptyEmbed = false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.sheldan.abstracto.core.templating.model;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class MetaEmbedConfiguration {
|
||||||
|
private Long additionalMessageLengthLimit;
|
||||||
|
private Long messageLimit;
|
||||||
|
|
||||||
|
private boolean preventEmptyEmbed;
|
||||||
|
private boolean allowsRoleMention;
|
||||||
|
private boolean allowsEveryoneMention;
|
||||||
|
@Builder.Default
|
||||||
|
private boolean allowsUserMention = true;
|
||||||
|
}
|
||||||
@@ -123,7 +123,10 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
List<String> messages = new ArrayList<>();
|
List<String> messages = new ArrayList<>();
|
||||||
String additionalMessage = embedConfiguration.getAdditionalMessage();
|
String additionalMessage = embedConfiguration.getAdditionalMessage();
|
||||||
if(additionalMessage != null) {
|
if(additionalMessage != null) {
|
||||||
Long segmentLimit = embedConfiguration.getAdditionalMessageLengthLimit() != null ? embedConfiguration.getAdditionalMessageLengthLimit() : Long.valueOf(Message.MAX_CONTENT_LENGTH);
|
Long segmentLimit = embedConfiguration.getMetaConfig() != null
|
||||||
|
&& embedConfiguration.getMetaConfig().getAdditionalMessageLengthLimit() != null ?
|
||||||
|
embedConfiguration.getMetaConfig().getAdditionalMessageLengthLimit() :
|
||||||
|
Long.valueOf(Message.MAX_CONTENT_LENGTH);
|
||||||
if(additionalMessage.length() > segmentLimit) {
|
if(additionalMessage.length() > segmentLimit) {
|
||||||
int segmentStart = 0;
|
int segmentStart = 0;
|
||||||
int segmentEnd = segmentLimit.intValue();
|
int segmentEnd = segmentLimit.intValue();
|
||||||
@@ -150,8 +153,8 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
if(serverContext.getServerId() != null) {
|
if(serverContext.getServerId() != null) {
|
||||||
messageLimit = Math.min(messageLimit, configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, serverContext.getServerId()));
|
messageLimit = Math.min(messageLimit, configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, serverContext.getServerId()));
|
||||||
}
|
}
|
||||||
if(embedConfiguration.getMessageLimit() != null) {
|
if(embedConfiguration.getMetaConfig() != null && embedConfiguration.getMetaConfig().getMessageLimit() != null) {
|
||||||
messageLimit = Math.min(messageLimit, embedConfiguration.getMessageLimit());
|
messageLimit = Math.min(messageLimit, embedConfiguration.getMetaConfig().getMessageLimit());
|
||||||
}
|
}
|
||||||
if(embeds.size() > messageLimit) {
|
if(embeds.size() > messageLimit) {
|
||||||
log.info("Limiting size of embeds. Max allowed: {}, currently: {}.", messageLimit, embeds.size());
|
log.info("Limiting size of embeds. Max allowed: {}, currently: {}.", messageLimit, embeds.size());
|
||||||
@@ -164,10 +167,23 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
|
|
||||||
return MessageToSend.builder()
|
return MessageToSend.builder()
|
||||||
.embeds(embeds)
|
.embeds(embeds)
|
||||||
|
.messageConfig(createMessageConfig(embedConfiguration.getMetaConfig()))
|
||||||
.messages(messages)
|
.messages(messages)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessageConfig createMessageConfig(MetaEmbedConfiguration metaEmbedConfiguration) {
|
||||||
|
if(metaEmbedConfiguration == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return MessageConfig
|
||||||
|
.builder()
|
||||||
|
.allowsEveryoneMention(metaEmbedConfiguration.isAllowsEveryoneMention())
|
||||||
|
.allowsUserMention(metaEmbedConfiguration.isAllowsUserMention())
|
||||||
|
.allowsRoleMention(metaEmbedConfiguration.isAllowsRoleMention())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
private void setPagingFooters(List<EmbedBuilder> embedBuilders) {
|
private void setPagingFooters(List<EmbedBuilder> embedBuilders) {
|
||||||
// the first footer comes from the configuration
|
// the first footer comes from the configuration
|
||||||
for (int i = 1; i < embedBuilders.size(); i++) {
|
for (int i = 1; i < embedBuilders.size(); i++) {
|
||||||
@@ -211,7 +227,7 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmptyEmbed(EmbedConfiguration configuration) {
|
private boolean isEmptyEmbed(EmbedConfiguration configuration) {
|
||||||
if (configuration.isPreventEmptyEmbed()) {
|
if (configuration.getMetaConfig() != null && configuration.getMetaConfig().isPreventEmptyEmbed()) {
|
||||||
return configuration.getFields() == null && configuration.getDescription() == null && configuration.getImageUrl() == null;
|
return configuration.getFields() == null && configuration.getDescription() == null && configuration.getImageUrl() == null;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<changeSet author="Sheldan" id="command_disabled_channel_group-table">
|
<changeSet author="Sheldan" id="command_disabled_channel_group-table">
|
||||||
<createTable tableName="command_disabled_channel_group">
|
<createTable tableName="command_disabled_channel_group">
|
||||||
<column name="id" type="BIGINT">
|
<column name="id" type="BIGINT">
|
||||||
<constraints nullable="true"/>
|
<constraints nullable="true" primaryKey="true" primaryKeyName="pk_disabled_channel_group"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
<constraints nullable="true"/>
|
<constraints nullable="true"/>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<changeSet author="Sheldan" id="cool_down_channel_group-table">
|
<changeSet author="Sheldan" id="cool_down_channel_group-table">
|
||||||
<createTable tableName="cool_down_channel_group">
|
<createTable tableName="cool_down_channel_group">
|
||||||
<column name="id" type="BIGINT">
|
<column name="id" type="BIGINT">
|
||||||
<constraints nullable="true"/>
|
<constraints nullable="true" primaryKey="true" primaryKeyName="pk_command_cooldown_channel_group"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
<constraints nullable="true"/>
|
<constraints nullable="true"/>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ public class AllowedMentionServiceBeanTest {
|
|||||||
public void getAllowedMentionTypesForServerEmpty() {
|
public void getAllowedMentionTypesForServerEmpty() {
|
||||||
allDefaultConfigAllowed();
|
allDefaultConfigAllowed();
|
||||||
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
||||||
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
||||||
Assert.assertNull(allowedMentions);
|
Assert.assertNull(allowedMentions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,9 +79,9 @@ public class AllowedMentionServiceBeanTest {
|
|||||||
when(allowedMentionConfig.getRole()).thenReturn(false);
|
when(allowedMentionConfig.getRole()).thenReturn(false);
|
||||||
when(allowedMentionConfig.getUser()).thenReturn(false);
|
when(allowedMentionConfig.getUser()).thenReturn(false);
|
||||||
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
||||||
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
||||||
Assert.assertEquals(1, allowedMentions.size());
|
Assert.assertEquals(1, allowedMentions.size());
|
||||||
Assert.assertEquals(Message.MentionType.EVERYONE, allowedMentions.get(0));
|
Assert.assertEquals(Message.MentionType.EVERYONE, allowedMentions.iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -89,7 +90,7 @@ public class AllowedMentionServiceBeanTest {
|
|||||||
when(allowedMentionConfig.getRole()).thenReturn(false);
|
when(allowedMentionConfig.getRole()).thenReturn(false);
|
||||||
when(allowedMentionConfig.getUser()).thenReturn(false);
|
when(allowedMentionConfig.getUser()).thenReturn(false);
|
||||||
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
|
||||||
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
|
||||||
Assert.assertEquals(0, allowedMentions.size());
|
Assert.assertEquals(0, allowedMentions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,9 +99,11 @@ public class TemplateServiceBeanTest {
|
|||||||
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
||||||
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
|
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
|
||||||
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
||||||
when(config.getAdditionalMessageLengthLimit()).thenReturn(2000L);
|
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
|
||||||
|
when(config.getMetaConfig()).thenReturn(metaConfig);
|
||||||
|
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(2000L);
|
||||||
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
||||||
when(config.getMessageLimit()).thenReturn(5L);
|
when(metaConfig.getMessageLimit()).thenReturn(5L);
|
||||||
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
||||||
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
||||||
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
|
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
|
||||||
@@ -117,9 +119,11 @@ public class TemplateServiceBeanTest {
|
|||||||
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
||||||
String templateContent = String.format("{ \"additionalMessage\": \"%s\", \"messageLimit\": 1}", additionalMessage);
|
String templateContent = String.format("{ \"additionalMessage\": \"%s\", \"messageLimit\": 1}", additionalMessage);
|
||||||
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
||||||
when(config.getAdditionalMessageLengthLimit()).thenReturn(2000L);
|
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
|
||||||
|
when(config.getMetaConfig()).thenReturn(metaConfig);
|
||||||
|
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(2000L);
|
||||||
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
||||||
when(config.getMessageLimit()).thenReturn(1L);
|
when(metaConfig.getMessageLimit()).thenReturn(1L);
|
||||||
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
||||||
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
||||||
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
|
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
|
||||||
@@ -134,8 +138,10 @@ public class TemplateServiceBeanTest {
|
|||||||
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
|
||||||
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
|
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
|
||||||
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
|
||||||
when(config.getAdditionalMessageLengthLimit()).thenReturn(500L);
|
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
|
||||||
when(config.getMessageLimit()).thenReturn(5L);
|
when(config.getMetaConfig()).thenReturn(metaConfig);
|
||||||
|
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(500L);
|
||||||
|
when(metaConfig.getMessageLimit()).thenReturn(5L);
|
||||||
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
|
||||||
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
|
||||||
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package dev.sheldan.abstracto.core.service;
|
|||||||
import dev.sheldan.abstracto.core.models.database.AllowedMention;
|
import dev.sheldan.abstracto.core.models.database.AllowedMention;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AllowedMentionService {
|
public interface AllowedMentionService {
|
||||||
boolean allMentionsAllowed(Long serverId);
|
boolean allMentionsAllowed(Long serverId);
|
||||||
List<Message.MentionType> getAllowedMentionTypesForServer(Long serverId);
|
Set<Message.MentionType> getAllowedMentionTypesForServer(Long serverId);
|
||||||
void allowMentionForServer(Message.MentionType mentionType, Long serverId);
|
void allowMentionForServer(Message.MentionType mentionType, Long serverId);
|
||||||
void disAllowMentionForServer(Message.MentionType mentionType, Long serverId);
|
void disAllowMentionForServer(Message.MentionType mentionType, Long serverId);
|
||||||
AllowedMention getDefaultAllowedMention();
|
AllowedMention getDefaultAllowedMention();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public interface PostTargetService {
|
|||||||
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTarget, Long serverId);
|
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTarget, Long serverId);
|
||||||
void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId);
|
void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId);
|
||||||
boolean postTargetDefinedInServer(PostTargetEnum name, Long serverId);
|
boolean postTargetDefinedInServer(PostTargetEnum name, Long serverId);
|
||||||
|
PostTarget getPostTarget(PostTargetEnum postTargetName, Long serverId);
|
||||||
boolean validPostTarget(String name);
|
boolean validPostTarget(String name);
|
||||||
List<PostTarget> getPostTargets(AServer server);
|
List<PostTarget> getPostTargets(AServer server);
|
||||||
List<String> getAvailablePostTargets();
|
List<String> getAvailablePostTargets();
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.abstracto.core.templating.model;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class MessageConfig {
|
||||||
|
private boolean allowsRoleMention;
|
||||||
|
private boolean allowsEveryoneMention;
|
||||||
|
@Builder.Default
|
||||||
|
private boolean allowsUserMention = true;
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ public class MessageToSend {
|
|||||||
* The file handle to send attached to the message.
|
* The file handle to send attached to the message.
|
||||||
*/
|
*/
|
||||||
private File fileToSend;
|
private File fileToSend;
|
||||||
|
private MessageConfig messageConfig;
|
||||||
|
|
||||||
public boolean hasFileToSend() {
|
public boolean hasFileToSend() {
|
||||||
return fileToSend != null;
|
return fileToSend != null;
|
||||||
|
|||||||
Reference in New Issue
Block a user