mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-29 17:02:40 +00:00
[AB-85] adding feature mode to automatically create a thread for suggestions
reworking post target service to function with optionals fixing trying to add reactions for suggestions if there was no message created not showing votes in case the buttons feature mode is active
This commit is contained in:
@@ -29,6 +29,8 @@ import dev.sheldan.abstracto.suggestion.service.management.SuggestionManagementS
|
||||
import dev.sheldan.abstracto.suggestion.service.management.SuggestionVoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -37,9 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@@ -131,6 +131,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
if(autoEvaluationEnabled) {
|
||||
autoEvaluateDays = configService.getLongValueOrConfigDefault(SUGGESTION_AUTO_EVALUATE_DAYS_CONFIG_KEY, serverId);
|
||||
}
|
||||
Instant autoEvaluationTargetDate = autoEvaluationEnabled ? Instant.now().plus(autoEvaluateDays, ChronoUnit.DAYS) : null;
|
||||
SuggestionLog model = SuggestionLog
|
||||
.builder()
|
||||
.suggestionId(newSuggestionId)
|
||||
@@ -143,7 +144,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
.suggester(suggester.getUser())
|
||||
.text(text)
|
||||
.autoEvaluationEnabled(autoEvaluationEnabled)
|
||||
.autoEvaluationTargetDate(autoEvaluationEnabled ? Instant.now().plus(autoEvaluateDays, ChronoUnit.DAYS) : null)
|
||||
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
||||
.build();
|
||||
if(useButtons) {
|
||||
setupButtonIds(model);
|
||||
@@ -151,22 +152,60 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_CREATION_TEMPLATE, model, serverId);
|
||||
log.info("Creating suggestion with id {} in server {} from member {}.", newSuggestionId, serverId, suggester.getIdLong());
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SuggestionPostTarget.SUGGESTION, serverId);
|
||||
List<ButtonConfigModel> buttonConfigModels = Arrays.asList(model.getAgreeButtonModel(), model.getDisAgreeButtonModel(), model.getRemoveVoteButtonModel());
|
||||
return FutureUtils.toSingleFutureGeneric(completableFutures)
|
||||
.thenCompose(aVoid -> self.addDeletionPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, model));
|
||||
.thenCompose(aVoid -> self.addVotingPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, buttonConfigModels, useButtons))
|
||||
.thenCompose(aVoid -> self.createSuggestionThread(serverId, newSuggestionId, suggester, text, autoEvaluationEnabled, autoEvaluationTargetDate));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addDeletionPossibility(Long suggestionChannelId, Long suggestionMessageId, String text, Member suggester, Long serverId,
|
||||
Long newSuggestionId, List<CompletableFuture<Message>> completableFutures, SuggestionLog model) {
|
||||
public CompletableFuture<Void> createSuggestionThread(Long serverId, Long suggestionId, Member suggester, String suggestionText,
|
||||
Boolean autoEvaluationEnabled, Instant autoEvaluationTargetDate) {
|
||||
if(featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_THREAD)) {
|
||||
Optional<GuildMessageChannel> suggestionTargetChannelOptional = postTargetService.getPostTargetChannel(SuggestionPostTarget.SUGGESTION, serverId);
|
||||
log.info("Trying to create thread for suggestion {} in server {}.", suggestionId, serverId);
|
||||
if (suggestionTargetChannelOptional.isPresent()) {
|
||||
GuildMessageChannel messageChannel = suggestionTargetChannelOptional.get();
|
||||
if(messageChannel instanceof IThreadContainer) {
|
||||
SuggestionThreadModel model = SuggestionThreadModel
|
||||
.builder()
|
||||
.suggestionId(suggestionId)
|
||||
.suggester(suggester.getUser())
|
||||
.member(suggester)
|
||||
.autoEvaluationEnabled(autoEvaluationEnabled)
|
||||
.text(suggestionText)
|
||||
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
||||
.build();
|
||||
IThreadContainer threadContainer = (IThreadContainer) messageChannel;
|
||||
String threadName = templateService.renderTemplate("suggestion_thread_name", model, serverId);
|
||||
return threadContainer.createThreadChannel(threadName).submit()
|
||||
.thenAccept(threadChannel -> log.info("Created thread for suggestion {} in server {}.", suggestionId, serverId));
|
||||
} else {
|
||||
log.info("Suggestion thread was not created - post target for suggestions does not allow to create threads");
|
||||
}
|
||||
} else {
|
||||
log.info("Suggestion thread was not created - post target did not evaluate to a channel or post target is disabled.");
|
||||
}
|
||||
} else {
|
||||
log.info("Suggestion thread feature disabled - not creating thread for suggestion {} in server {}.", suggestionId, serverId);
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addVotingPossibility(Long suggestionChannelId, Long suggestionMessageId, String text, Member suggester, Long serverId,
|
||||
Long newSuggestionId, List<CompletableFuture<Message>> completableFutures, List<ButtonConfigModel> buttonConfigModels,
|
||||
Boolean useButtons) {
|
||||
if(!completableFutures.isEmpty()) {
|
||||
Message message = completableFutures.get(0).join();
|
||||
if(model.getUseButtons()) {
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getAgreeButtonModel(), SuggestionDecision.AGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getDisAgreeButtonModel(), SuggestionDecision.DISAGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getRemoveVoteButtonModel(), SuggestionDecision.REMOVE_VOTE);
|
||||
if(useButtons) {
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(0), SuggestionDecision.AGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(1), SuggestionDecision.DISAGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(2), SuggestionDecision.REMOVE_VOTE);
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
componentPayloadManagementService.createButtonPayload(model.getAgreeButtonModel(), server);
|
||||
componentPayloadManagementService.createButtonPayload(model.getDisAgreeButtonModel(), server);
|
||||
componentPayloadManagementService.createButtonPayload(model.getRemoveVoteButtonModel(), server);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(0), server);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(1), server);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(2), server);
|
||||
self.persistSuggestionInDatabase(suggester, text, message, newSuggestionId, suggestionChannelId, suggestionMessageId);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
@@ -178,6 +217,9 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
self.persistSuggestionInDatabase(suggester, text, message, newSuggestionId, suggestionChannelId, suggestionMessageId);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureDecisionButtonPayload(Long serverId, Long newSuggestionId, ButtonConfigModel model, SuggestionDecision decision) {
|
||||
@@ -275,6 +317,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
Long serverId = suggestion.getServer().getId();
|
||||
Long channelId = suggestion.getChannel().getId();
|
||||
Long originalMessageId = suggestion.getMessageId();
|
||||
boolean buttonsActive = featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_BUTTONS);
|
||||
Long agreements = suggestionVoteManagementService.getDecisionsForSuggestion(suggestion, SuggestionDecision.AGREE);
|
||||
Long disagreements = suggestionVoteManagementService.getDecisionsForSuggestion(suggestion, SuggestionDecision.DISAGREE);
|
||||
Long suggestionId = suggestion.getSuggestionId().getId();
|
||||
@@ -290,6 +333,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
.suggestionId(suggestionId)
|
||||
.state(suggestion.getState())
|
||||
.serverId(serverId)
|
||||
.buttonsActive(buttonsActive)
|
||||
.member(memberExecutingCommand)
|
||||
.agreeVotes(agreements)
|
||||
.disAgreeVotes(disagreements)
|
||||
|
||||
@@ -11,6 +11,10 @@ abstracto.featureModes.suggestionReminder.featureName=suggestion
|
||||
abstracto.featureModes.suggestionReminder.mode=suggestionReminder
|
||||
abstracto.featureModes.suggestionReminder.enabled=false
|
||||
|
||||
abstracto.featureModes.suggestionThread.featureName=suggestion
|
||||
abstracto.featureModes.suggestionThread.mode=suggestionThread
|
||||
abstracto.featureModes.suggestionThread.enabled=false
|
||||
|
||||
abstracto.systemConfigs.suggestionReminderDays.name=suggestionReminderDays
|
||||
abstracto.systemConfigs.suggestionReminderDays.longValue=7
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ public class SuggestionFeatureConfig implements FeatureConfig {
|
||||
return Arrays.asList(
|
||||
SuggestionFeatureMode.SUGGESTION_REMINDER,
|
||||
SuggestionFeatureMode.SUGGESTION_BUTTONS,
|
||||
SuggestionFeatureMode.SUGGESTION_AUTO_EVALUATE);
|
||||
SuggestionFeatureMode.SUGGESTION_AUTO_EVALUATE,
|
||||
SuggestionFeatureMode.SUGGESTION_THREAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,10 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum SuggestionFeatureMode implements FeatureMode {
|
||||
SUGGESTION_REMINDER("suggestionReminder"), SUGGESTION_BUTTONS("suggestionButton"), SUGGESTION_AUTO_EVALUATE("suggestionAutoEvaluate");
|
||||
SUGGESTION_REMINDER("suggestionReminder"),
|
||||
SUGGESTION_BUTTONS("suggestionButton"),
|
||||
SUGGESTION_AUTO_EVALUATE("suggestionAutoEvaluate"),
|
||||
SUGGESTION_THREAD("suggestionThread");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class SuggestionThreadModel {
|
||||
private Long suggestionId;
|
||||
private User suggester;
|
||||
private Member member;
|
||||
private String text;
|
||||
private Long serverId;
|
||||
private Instant autoEvaluationTargetDate;
|
||||
private Boolean autoEvaluationEnabled;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.dv8tion.jda.api.entities.User;
|
||||
public class SuggestionUpdateModel {
|
||||
private Long suggestionId;
|
||||
private SuggestionState state;
|
||||
private Boolean buttonsActive;
|
||||
private User suggester;
|
||||
private Member member;
|
||||
private String text;
|
||||
|
||||
@@ -68,25 +68,26 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
GuildMessageChannel messageChannelForPostTarget = getMessageChannelForPostTarget(target);
|
||||
log.debug("Sending message embed to post target {}.", target.getName());
|
||||
return channelService.sendEmbedToChannel(embed, messageChannelForPostTarget);
|
||||
return getMessageChannelForPostTarget(target)
|
||||
.map(channel -> channelService.sendEmbedToChannel(embed, channel))
|
||||
.orElse(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
}
|
||||
|
||||
private GuildMessageChannel getMessageChannelForPostTarget(PostTarget target) {
|
||||
private Optional<GuildMessageChannel> getMessageChannelForPostTarget(PostTarget target) {
|
||||
Guild guild = botService.getInstance().getGuildById(target.getServerReference().getId());
|
||||
if (guild != null) {
|
||||
GuildChannel guildChannelById = guild.getGuildChannelById(target.getChannelReference().getId());
|
||||
if (guildChannelById instanceof GuildMessageChannel) {
|
||||
return (GuildMessageChannel) guildChannelById;
|
||||
return Optional.of((GuildMessageChannel) guildChannelById);
|
||||
} else {
|
||||
log.error("Incorrect post target configuration (it is not a message channel): {} points to {} on server {}", target.getName(),
|
||||
target.getChannelReference().getId(), target.getServerReference().getId());
|
||||
throw new ChannelNotInGuildException(target.getChannelReference().getId());
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
throw new GuildNotFoundException(target.getServerReference().getId());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +144,10 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
log.debug("Send messageToSend towards post target {}.", target.getName());
|
||||
return channelService.sendMessageToSendToChannel(message, guildMessageChannel);
|
||||
return getMessageChannelForPostTarget(target)
|
||||
.map(channel -> channelService.sendMessageToSendToChannel(message, channel))
|
||||
.orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,16 +157,17 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
return getMessageChannelForPostTarget(target).map(messageChannel -> {
|
||||
// always takes the first one, only applicable for this scenario
|
||||
String messageText = message.getMessages().get(0);
|
||||
if (StringUtils.isBlank(messageText)) {
|
||||
log.debug("Editing embeds of message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), guildMessageChannel, messageId));
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), messageChannel, messageId));
|
||||
} else {
|
||||
log.debug("Editing message text and potentially text for message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), guildMessageChannel, messageId));
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), messageChannel, messageId));
|
||||
}
|
||||
}).orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +178,18 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
return getMessageChannelForPostTarget(target).map(messageChannel -> {
|
||||
CompletableFuture<Message> messageEditFuture = new CompletableFuture<>();
|
||||
futures.add(messageEditFuture);
|
||||
if (StringUtils.isBlank(messageToSend.getMessages().get(0).trim())) {
|
||||
channelService.retrieveMessageInChannel(guildMessageChannel, messageId).thenAccept(message -> {
|
||||
channelService.retrieveMessageInChannel(messageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message embeds in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when upserting message embeds for message {} in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
@@ -196,14 +199,14 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
channelService.retrieveMessageInChannel(guildMessageChannel, messageId).thenAccept(message -> {
|
||||
channelService.retrieveMessageInChannel(messageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getMessages().get(0), messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when trying to upsert a message {} in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
@@ -213,8 +216,8 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return futures;
|
||||
}).orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,16 +231,16 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
public void throwIfPostTargetIsNotDefined(PostTargetEnum targetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(targetEnum, serverId);
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
throw new PostTargetNotValidException(name.getKey(), defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
throw new PostTargetNotValidException(targetEnum.getKey(), defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postTargetDefinedInServer(PostTargetEnum name, Long serverId) {
|
||||
return postTargetManagement.postTargetExists(name.getKey(), serverId);
|
||||
public boolean postTargetDefinedInServer(PostTargetEnum targetEnum, Long serverId) {
|
||||
return postTargetManagement.postTargetExists(targetEnum.getKey(), serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -260,15 +263,15 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validatePostTarget(PostTargetEnum name, Long serverId) {
|
||||
if(!postTargetUsableInServer(name, serverId)) {
|
||||
throw new PostTargetNotUsableException(name.getKey());
|
||||
public void validatePostTarget(PostTargetEnum targetEnum, Long serverId) {
|
||||
if (!postTargetUsableInServer(targetEnum, serverId)) {
|
||||
throw new PostTargetNotUsableException(targetEnum.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postTargetUsableInServer(PostTargetEnum name, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
public boolean postTargetUsableInServer(PostTargetEnum targetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(targetEnum, serverId);
|
||||
return postTargetOptional.isPresent() && !postTargetOptional.get().getDisabled();
|
||||
}
|
||||
|
||||
@@ -305,4 +308,16 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
|
||||
postTarget.setDisabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GuildMessageChannel> getPostTargetChannel(PostTargetEnum postTargetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTarget = getPostTarget(postTargetEnum, serverId);
|
||||
return postTarget.flatMap(target -> {
|
||||
if (target.getDisabled()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return getMessageChannelForPostTarget(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface PostTargetService {
|
||||
@@ -23,14 +25,15 @@ public interface PostTargetService {
|
||||
List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTargetEnum postTargetName, Long serverId);
|
||||
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target);
|
||||
List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTarget, Long serverId);
|
||||
void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId);
|
||||
boolean postTargetDefinedInServer(PostTargetEnum name, Long serverId);
|
||||
void throwIfPostTargetIsNotDefined(PostTargetEnum targetEnum, Long serverId);
|
||||
boolean postTargetDefinedInServer(PostTargetEnum targetEnum, Long serverId);
|
||||
boolean validPostTarget(String name);
|
||||
void validatePostTarget(PostTargetEnum name, Long serverId);
|
||||
boolean postTargetUsableInServer(PostTargetEnum name, Long serverId);
|
||||
void validatePostTarget(PostTargetEnum targetEnum, Long serverId);
|
||||
boolean postTargetUsableInServer(PostTargetEnum targetEnum, Long serverId);
|
||||
List<PostTarget> getPostTargets(AServer server);
|
||||
List<String> getAvailablePostTargets();
|
||||
List<String> getPostTargetsOfEnabledFeatures(AServer server);
|
||||
void disablePostTarget(String name, Long serverId);
|
||||
void enablePostTarget(String name, Long serverId);
|
||||
Optional<GuildMessageChannel> getPostTargetChannel(PostTargetEnum postTargetEnum, Long serverId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user