[AB-242] refactoring suggestions

adding veto and unsuggest command
adding support for configuration whether or not a reply mentions the message
adding support to reply to a message via template
changed default mention config to exclude role mentions
This commit is contained in:
Sheldan
2021-04-29 01:00:27 +02:00
parent dec398c3f1
commit 020cc58c4a
38 changed files with 524 additions and 243 deletions

View File

@@ -51,7 +51,7 @@ public class InteractiveServiceBean implements InteractiveService {
@Override
public void createMessageWithResponse(MessageToSend messageToSend, AUserInAServer responder, AChannel channel, Long messageId, Consumer<MessageReceivedEvent> action, Runnable finalAction) {
channelService.sendMessageToSendToAChannel(messageToSend, channel);
channelService.sendMessageEmbedToSendToAChannel(messageToSend, channel);
Long userId = responder.getUserReference().getId();
eventWaiter.waitForEvent(MessageReceivedEvent.class, event -> {
if(event != null) {

View File

@@ -184,7 +184,7 @@ public class ChannelServiceBean implements ChannelService {
}
@Override
public List<CompletableFuture<Message>> sendMessageToSendToAChannel(MessageToSend messageToSend, AChannel channel) {
public List<CompletableFuture<Message>> sendMessageEmbedToSendToAChannel(MessageToSend messageToSend, AChannel channel) {
Optional<TextChannel> textChannelFromServer = getTextChannelFromServerOptional(channel.getServer().getId(), channel.getId());
if(textChannelFromServer.isPresent()) {
return sendMessageToSendToChannel(messageToSend, textChannelFromServer.get());
@@ -193,7 +193,7 @@ public class ChannelServiceBean implements ChannelService {
}
@Override
public CompletableFuture<Message> sendMessageToSendToAChannel(MessageToSend messageToSend, AChannel channel, Integer embedIndex) {
public CompletableFuture<Message> sendMessageEmbedToSendToAChannel(MessageToSend messageToSend, AChannel channel, Integer embedIndex) {
return sendEmbedToAChannel(messageToSend.getEmbeds().get(embedIndex), channel);
}
@@ -244,9 +244,15 @@ public class ChannelServiceBean implements ChannelService {
}
}
Set<Message.MentionType> allowedMentions = getAllowedMentionsFor(textChannel, messageToSend);
allMessageActions.forEach(messageAction ->
futures.add(messageAction.allowedMentions(allowedMentions).submit())
);
allMessageActions.forEach(messageAction -> {
if(messageToSend.getReferencedMessageId() != null) {
messageAction = messageAction.referenceById(messageToSend.getReferencedMessageId());
if(messageToSend.getMessageConfig() != null && !messageToSend.getMessageConfig().isMentionsReferencedMessage()) {
messageAction = messageAction.mentionRepliedUser(false);
}
}
futures.add(messageAction.allowedMentions(allowedMentions).submit());
});
return futures;
}
@@ -284,6 +290,9 @@ public class ChannelServiceBean implements ChannelService {
throw new IllegalArgumentException("Message to send did not contain anything to send.");
}
}
if(messageToSend.getReferencedMessageId() != null) {
messageAction = messageAction.referenceById(messageToSend.getReferencedMessageId());
}
metricService.incrementCounter(MESSAGE_EDIT_METRIC);
return messageAction.submit();
}

View File

@@ -80,7 +80,7 @@ public class MessageServiceBean implements MessageService {
@Override
public CompletableFuture<Message> createStatusMessage(MessageToSend messageToSend, AChannel channel) {
return channelService.sendMessageToSendToAChannel(messageToSend, channel).get(0);
return channelService.sendMessageEmbedToSendToAChannel(messageToSend, channel).get(0);
}
@Override

View File

@@ -51,6 +51,7 @@ public class EmbedConfiguration {
* The {@link OffsetDateTime} object used as the time stamp in the {@link net.dv8tion.jda.api.entities.MessageEmbed}
*/
private OffsetDateTime timeStamp;
private Long referencedMessageId;
/**
* The message which is posted along the {@link net.dv8tion.jda.api.entities.MessageEmbed} as a normal message.
*/

View File

@@ -16,4 +16,6 @@ public class MetaEmbedConfiguration {
private boolean allowsEveryoneMention;
@Builder.Default
private boolean allowsUserMention = true;
@Builder.Default
private boolean mentionsReferencedMessage = true;
}

View File

@@ -164,11 +164,13 @@ public class TemplateServiceBean implements TemplateService {
log.info("Limiting size of messages. Max allowed: {}, currently: {}.", messageLimit, messages.size());
messages.subList(messageLimit.intValue(), messages.size()).clear();
}
Long referencedMessageId = embedConfiguration.getReferencedMessageId();
return MessageToSend.builder()
.embeds(embeds)
.messageConfig(createMessageConfig(embedConfiguration.getMetaConfig()))
.messages(messages)
.referencedMessageId(referencedMessageId)
.build();
}
@@ -181,6 +183,7 @@ public class TemplateServiceBean implements TemplateService {
.allowsEveryoneMention(metaEmbedConfiguration.isAllowsEveryoneMention())
.allowsUserMention(metaEmbedConfiguration.isAllowsUserMention())
.allowsRoleMention(metaEmbedConfiguration.isAllowsRoleMention())
.mentionsReferencedMessage(metaEmbedConfiguration.isMentionsReferencedMessage())
.build();
}

View File

@@ -4,7 +4,7 @@ abstracto.eventWaiter.threads=10
server.port=8080
abstracto.allowedmention.everyone=false
abstracto.allowedmention.role=true
abstracto.allowedmention.role=false
abstracto.allowedmention.user=true
abstracto.systemConfigs.prefix.name=prefix