mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-24 22:43:37 +00:00
addressed sonar code smells
This commit is contained in:
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.experience.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.ServerConfigListener;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.management.ConfigManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -162,7 +162,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
if(!roleService.hasAnyOfTheRoles(member, disabledRoles)) {
|
||||
log.trace("Handling {}. The user gains {}", userInAServer.getUserReference().getId(), gainedExperience);
|
||||
AUserExperience aUserExperience = userExperienceManagementService.incrementExpForUser(userInAServer, gainedExperience.longValue(), 1L);
|
||||
if(!aUserExperience.getExperienceGainDisabled()) {
|
||||
if(Boolean.FALSE.equals(aUserExperience.getExperienceGainDisabled())) {
|
||||
updateUserlevel(aUserExperience, levels);
|
||||
updateUserRole(aUserExperience, roles);
|
||||
userExperienceManagementService.saveUser(aUserExperience);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class UserExperienceManagementServiceBean implements UserExperienceManage
|
||||
Optional<AUserExperience> byId = repository.findById(user.getUserInServerId());
|
||||
if(byId.isPresent()) {
|
||||
AUserExperience userExperience = byId.get();
|
||||
if(!userExperience.getExperienceGainDisabled()) {
|
||||
if(Boolean.FALSE.equals(userExperience.getExperienceGainDisabled())) {
|
||||
userExperience.setMessageCount(userExperience.getMessageCount() + messageCount);
|
||||
userExperience.setExperience(userExperience.getExperience() + experience);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DecayAllWarnings extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Boolean logWarnings = !parameters.isEmpty() ? (Boolean) parameters.get(0) : Boolean.FALSE;
|
||||
boolean logWarnings = !parameters.isEmpty() ? (Boolean) parameters.get(0) : Boolean.FALSE;
|
||||
warnService.decayAllWarningsForServer(commandContext.getUserInitiatedContext().getServer(), logWarnings);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -7,13 +7,10 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.config.ModerationModule;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Warnings extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Warning> warnsToDisplay;
|
||||
if(commandContext.getParameters().getParameters().size() > 0) {
|
||||
if(!commandContext.getParameters().getParameters().isEmpty()) {
|
||||
Member member = (Member) commandContext.getParameters().getParameters().get(0);
|
||||
warnsToDisplay = warnManagementService.getAllWarnsForUser(userInServerManagementService.loadUser(member));
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.HashMap;
|
||||
public class JoinLogger implements JoinListener {
|
||||
|
||||
private static final String USER_JOIN_TEMPLATE = "user_join";
|
||||
private static final String JOIN_LOG_TARGET = "joinLog";
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class MessageDeleteLogListener implements MessageDeletedListener {
|
||||
|
||||
private static final String DELETE_LOG_TARGET = "deleteLog";
|
||||
private static final String MESSAGE_DELETED_TEMPLATE = "message_deleted";
|
||||
private static final String MESSAGE_DELETED_ATTACHMENT_TEMPLATE = "message_deleted_attachment";
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ public class MuteServiceBean implements MuteService {
|
||||
|
||||
private static final String MUTE_LOG_TEMPLATE = "mute_log";
|
||||
private static final String UNMUTE_LOG_TEMPLATE = "unmute_log";
|
||||
private static final String MUTE_LOG_TARGET = "muteLog";
|
||||
private static final String MUTE_NOTIFICATION_TEMPLATE = "mute_notification";
|
||||
|
||||
@Override
|
||||
@@ -225,7 +224,7 @@ public class MuteServiceBean implements MuteService {
|
||||
// but if the person gets unmuted immediately, via command, this might still execute of the instant unmute
|
||||
// so we need to load the mute, and check if the mute was unmuted already, because the mute object we have at
|
||||
// hand was loaded earlier, and does not reflect the true state
|
||||
if(updatedMute.getMuteEnded()) {
|
||||
if(Boolean.TRUE.equals(updatedMute.getMuteEnded())) {
|
||||
log.info("Mute {} has ended already, {} does not need to be unmuted anymore.", mute.getId(), mute.getMutedUser().getUserReference().getId());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public class WarnServiceBean implements WarnService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decayAllWarningsForServer(AServer server, Boolean logWarnings) {
|
||||
public void decayAllWarningsForServer(AServer server, boolean logWarnings) {
|
||||
List<Warning> warningsToDecay = warnManagementService.getActiveWarningsInServerOlderThan(server, Instant.now());
|
||||
decayWarnings(warningsToDecay);
|
||||
if(logWarnings) {
|
||||
|
||||
@@ -15,5 +15,5 @@ public interface WarnService {
|
||||
Warning warnUser(FullUser warnedUser, FullUser warningUser, String reason, TextChannel feedbackChannel);
|
||||
void warnUserWithLog(Member warnedMember, Member warningMember, String reason, WarnLog warnLog, TextChannel feedbackChannel);
|
||||
void decayWarningsForServer(AServer server);
|
||||
void decayAllWarningsForServer(AServer server, Boolean logWarnings);
|
||||
void decayAllWarningsForServer(AServer server, boolean logWarnings);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ModMailMessageServiceBean implements ModMailMessageService {
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> loadModMailMessages(List<ModMailMessage> modMailMessages) {
|
||||
if(modMailMessages.size() == 0) {
|
||||
if(modMailMessages.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
ModMailThread thread = modMailMessages.get(0).getThreadReference();
|
||||
@@ -34,7 +34,7 @@ public class ModMailMessageServiceBean implements ModMailMessageService {
|
||||
ServerChannelMessage.ServerChannelMessageBuilder serverChannelMessageBuilder = ServerChannelMessage
|
||||
.builder()
|
||||
.messageId(modMailMessage.getMessageId());
|
||||
if(!modMailMessage.getDmChannel()) {
|
||||
if(Boolean.FALSE.equals(modMailMessage.getDmChannel())) {
|
||||
serverChannelMessageBuilder
|
||||
.channelId(modMailMessage.getThreadReference().getChannel().getId())
|
||||
.serverId(modMailMessage.getThreadReference().getServer().getId());
|
||||
@@ -42,9 +42,7 @@ public class ModMailMessageServiceBean implements ModMailMessageService {
|
||||
messageIds.add(serverChannelMessageBuilder.build());
|
||||
});
|
||||
List<CompletableFuture<Message>> messageFutures = new ArrayList<>();
|
||||
modMailMessages.forEach(modMailMessage -> {
|
||||
messageFutures.add(new CompletableFuture<>());
|
||||
});
|
||||
modMailMessages.forEach(modMailMessage -> messageFutures.add(new CompletableFuture<>()));
|
||||
Optional<TextChannel> textChannelFromServer = botService.getTextChannelFromServer(thread.getServer().getId(), thread.getChannel().getId());
|
||||
if(textChannelFromServer.isPresent()) {
|
||||
TextChannel modMailThread = textChannelFromServer.get();
|
||||
@@ -52,16 +50,12 @@ public class ModMailMessageServiceBean implements ModMailMessageService {
|
||||
Iterator<CompletableFuture<Message>> iterator = messageFutures.iterator();
|
||||
messageIds.forEach(serverChannelMessage -> {
|
||||
if(serverChannelMessage.getChannelId() == null){
|
||||
privateChannel.retrieveMessageById(serverChannelMessage.getMessageId()).queue(message -> {
|
||||
iterator.next().complete(message);
|
||||
}, throwable -> {
|
||||
privateChannel.retrieveMessageById(serverChannelMessage.getMessageId()).queue(message -> iterator.next().complete(message), throwable -> {
|
||||
log.info("Failed to load message in private channel with user {}", thread.getUser().getUserReference().getId());
|
||||
iterator.next().complete(null);
|
||||
});
|
||||
} else {
|
||||
modMailThread.retrieveMessageById(serverChannelMessage.getMessageId()).queue(message -> {
|
||||
iterator.next().complete(message);
|
||||
}, throwable -> {
|
||||
modMailThread.retrieveMessageById(serverChannelMessage.getMessageId()).queue(message -> iterator.next().complete(message), throwable -> {
|
||||
log.info("Failed to load message {} in thread {}", serverChannelMessage.getMessageId(), modMailThread.getIdLong());
|
||||
iterator.next().complete(null);
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
|
||||
|
||||
@Override
|
||||
public void createModMailThreadForUser(FullUser aUserInAServer, Message initialMessage, MessageChannel feedBackChannel, Boolean userInitiated) {
|
||||
public void createModMailThreadForUser(FullUser aUserInAServer, Message initialMessage, MessageChannel feedBackChannel, boolean userInitiated) {
|
||||
Long categoryId = configService.getLongValue(MODMAIL_CATEGORY, aUserInAServer.getAUserInAServer().getServerReference().getId());
|
||||
User user = aUserInAServer.getMember().getUser();
|
||||
CompletableFuture<TextChannel> textChannel = channelService.createTextChannel(user.getName() + user.getDiscriminator(), aUserInAServer.getAUserInAServer().getServerReference(), categoryId);
|
||||
@@ -127,7 +127,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void performModMailThreadSetup(FullUser aUserInAServer, Message initialMessage, TextChannel channel, Boolean userInitiated, List<UndoActionInstance> undoActions) {
|
||||
public void performModMailThreadSetup(FullUser aUserInAServer, Message initialMessage, TextChannel channel, boolean userInitiated, List<UndoActionInstance> undoActions) {
|
||||
try {
|
||||
ModMailThread thread = createThreadObject(channel, aUserInAServer);
|
||||
sendModMailHeader(channel, aUserInAServer, undoActions);
|
||||
@@ -191,7 +191,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
@Override
|
||||
public void createModMailPrompt(AUser user, Message initialMessage) {
|
||||
List<AUserInAServer> knownServers = userInServerManagementService.getUserInAllServers(user.getId());
|
||||
if(knownServers.size() > 0) {
|
||||
if(!knownServers.isEmpty()) {
|
||||
List<ServerChoice> availableGuilds = new ArrayList<>();
|
||||
HashMap<String, AUserInAServer> choices = new HashMap<>();
|
||||
for (int i = 0; i < knownServers.size(); i++) {
|
||||
@@ -209,7 +209,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
availableGuilds.add(serverChoice);
|
||||
}
|
||||
}
|
||||
if(availableGuilds.size() > 0) {
|
||||
if(availableGuilds.size() > 1) {
|
||||
ModMailServerChooserModel modMailServerChooserModel = ModMailServerChooserModel
|
||||
.builder()
|
||||
.commonGuilds(availableGuilds)
|
||||
@@ -294,9 +294,9 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_user_message", modMailUserReplyModel);
|
||||
List<CompletableFuture<Message>> completableFutures = channelService.sendMessageToSendToChannel(messageToSend, textChannel);
|
||||
return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
self.postProcessSendMessages(modMailThreadId, message, completableFutures);
|
||||
});
|
||||
return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
self.postProcessSendMessages(modMailThreadId, message, completableFutures)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -324,15 +324,15 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relayMessageToDm(ModMailThread modMailThread, String text, Message message, Boolean anonymous, MessageChannel feedBack) {
|
||||
public void relayMessageToDm(ModMailThread modMailThread, String text, Message message, boolean anonymous, MessageChannel feedBack) {
|
||||
Long modMailThreadId = modMailThread.getId();
|
||||
User userById = botService.getInstance().getUserById(modMailThread.getUser().getUserReference().getId());
|
||||
if(userById != null) {
|
||||
userById.openPrivateChannel().queue(privateChannel -> {
|
||||
self.sendReply(modMailThreadId, text, message, privateChannel, anonymous, feedBack);
|
||||
}, throwable -> {
|
||||
log.warn("Failed to open private channel with user {}", userById.getIdLong());
|
||||
});
|
||||
userById.openPrivateChannel().queue(privateChannel ->
|
||||
self.sendReply(modMailThreadId, text, message, privateChannel, anonymous, feedBack)
|
||||
,throwable ->
|
||||
log.warn("Failed to open private channel with user {}", userById.getIdLong())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,14 +363,14 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser) {
|
||||
public synchronized void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, boolean notifyUser) {
|
||||
AFeatureMode aFeatureMode = featureModeService.getFeatureMode(ModMailFeatures.MOD_MAIL, modMailThread.getServer());
|
||||
boolean loggingMode = aFeatureMode.getMode().equalsIgnoreCase(ModMailMode.LOGGING.getKey());
|
||||
closeModMailThread(modMailThread, feedBack, note, notifyUser, loggingMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser, Boolean logThread) {
|
||||
public void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, boolean notifyUser, boolean logThread) {
|
||||
Long modMailThreadId = modMailThread.getId();
|
||||
log.info("Starting closing procedure for thread {}", modMailThread.getId());
|
||||
List<ModMailMessage> modMailMessages = modMailThread.getMessages();
|
||||
@@ -612,9 +612,9 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
ModMailModeratorReplyModel modMailUserReplyModel = modMailModeratorReplyModelBuilder.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_staff_message", modMailUserReplyModel);
|
||||
List<CompletableFuture<Message>> completableFutures = channelService.sendMessageToSendToChannel(messageToSend, privateChannel);
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
self.saveSendMessagesAndUpdateState(modMailThreadId, anonymous, moderator, completableFutures);
|
||||
}).exceptionally(throwable -> {
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
self.saveSendMessagesAndUpdateState(modMailThreadId, anonymous, moderator, completableFutures)
|
||||
).exceptionally(throwable -> {
|
||||
log.error("Failed to send message to user {}", modMailThread.getUser().getUserReference().getId());
|
||||
sendModMailFailure("modmail_exception_cannot_message_user", modMailThread.getUser(), modMailThread.getId(), feedBack, throwable);
|
||||
return null;
|
||||
@@ -650,8 +650,8 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
}
|
||||
|
||||
public void saveMessageIds(List<Message> messages, ModMailThread modMailThread, AUserInAServer author, Boolean anonymous, Boolean inDmChannel) {
|
||||
messages.forEach(message -> {
|
||||
modMailMessageManagementService.addMessageToThread(modMailThread, message, author, anonymous, inDmChannel);
|
||||
});
|
||||
messages.forEach(message ->
|
||||
modMailMessageManagementService.addMessageToThread(modMailThread, message, author, anonymous, inDmChannel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.modmail.setup;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.interactive.*;
|
||||
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
|
||||
@@ -94,7 +93,7 @@ public class ModMailCategorySetupBean implements ModMailCategorySetup {
|
||||
Guild guild = botService.getGuildByIdNullable(user.getGuildId());
|
||||
FeatureValidationResult featureValidationResult = FeatureValidationResult.builder().validationResult(true).build();
|
||||
modMailFeatureValidator.validateModMailCategory(featureValidationResult, guild, categoryId);
|
||||
if(featureValidationResult.getValidationResult()) {
|
||||
if(Boolean.FALSE.equals(featureValidationResult.getValidationResult())) {
|
||||
AConfig fakeValue = configService.getFakeConfigForValue(ModMailThreadServiceBean.MODMAIL_CATEGORY, user.getGuildId(), messageContent);
|
||||
ModMailCategoryDelayedActionConfig build = ModMailCategoryDelayedActionConfig
|
||||
.builder()
|
||||
@@ -128,9 +127,7 @@ public class ModMailCategorySetupBean implements ModMailCategorySetup {
|
||||
}
|
||||
|
||||
protected Runnable getTimeoutRunnable(Long serverId, Long channelId) {
|
||||
return () -> {
|
||||
interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
};
|
||||
return () -> interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
}
|
||||
|
||||
protected boolean checkForExit(Message message) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.HashMap;
|
||||
|
||||
public class ModMailThreadNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long modMailThreadId;
|
||||
private final Long modMailThreadId;
|
||||
|
||||
public ModMailThreadNotFoundException(Long modMailThreadId) {
|
||||
super("");
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.modmail.models.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.*;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@@ -10,13 +10,13 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
||||
public interface ModMailThreadService {
|
||||
void createModMailThreadForUser(FullUser userInAServer, Message initialMessage, MessageChannel feedBackChannel, Boolean userInitiated);
|
||||
void createModMailThreadForUser(FullUser userInAServer, Message initialMessage, MessageChannel feedBackChannel, boolean userInitiated);
|
||||
boolean hasOpenThread(AUserInAServer aUserInAServer);
|
||||
boolean hasOpenThread(AUser user);
|
||||
void setModMailCategoryTo(AServer server, Long categoryId);
|
||||
void createModMailPrompt(AUser user, Message initialMessage);
|
||||
void relayMessageToModMailThread(ModMailThread modMailThread, Message message);
|
||||
void relayMessageToDm(ModMailThread modMailThread, String text, Message message, Boolean anonymous, MessageChannel feedBack);
|
||||
void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser);
|
||||
void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser, Boolean logThread);
|
||||
void relayMessageToDm(ModMailThread modMailThread, String text, Message message, boolean anonymous, MessageChannel feedBack);
|
||||
void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, boolean notifyUser);
|
||||
void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, boolean notifyUser, boolean logThread);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ public class MessageEmbedListener implements MessageReceivedListener {
|
||||
for (MessageEmbedLink messageEmbedLink : links) {
|
||||
messageRaw = messageRaw.replace(messageEmbedLink.getWholeUrl(), "");
|
||||
Long userEmbeddingUserInServerId = userInServerManagementService.loadUser(message.getMember()).getUserInServerId();
|
||||
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage -> {
|
||||
self.loadUserAndEmbed(message, userEmbeddingUserInServerId, cachedMessage);
|
||||
};
|
||||
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage ->self.loadUserAndEmbed(message, userEmbeddingUserInServerId, cachedMessage);
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessageConsumer)
|
||||
.exceptionally(throwable -> {
|
||||
log.error("Error when embedding link for message {}", message.getId(), throwable);
|
||||
|
||||
@@ -98,16 +98,15 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
|
||||
|
||||
@Override
|
||||
public void embedLinks(List<MessageEmbedLink> linksToEmbed, TextChannel target, Long userEmbeddingUserInServerId, Message embeddingMessage) {
|
||||
linksToEmbed.forEach(messageEmbedLink -> {
|
||||
linksToEmbed.forEach(messageEmbedLink ->
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId())
|
||||
.thenAccept(cachedMessage -> {
|
||||
self.embedLink(cachedMessage, target, userEmbeddingUserInServerId, embeddingMessage);
|
||||
}
|
||||
.thenAccept(cachedMessage -> self.embedLink(cachedMessage, target, userEmbeddingUserInServerId, embeddingMessage)
|
||||
|
||||
).exceptionally(throwable -> {
|
||||
log.error("Message retrieval from cache failed for message {}.", messageEmbedLink.getMessageId(), throwable);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,18 +83,16 @@ public class StarboardServiceBean implements StarboardService {
|
||||
public void createStarboardPost(CachedMessage message, List<AUserInAServer> userExceptAuthor, AUserInAServer userReacting, AUserInAServer starredUser) {
|
||||
StarboardPostModel starboardPostModel = buildStarboardPostModel(message, userExceptAuthor.size());
|
||||
List<Long> userExceptAuthorIds = new ArrayList<>();
|
||||
userExceptAuthor.forEach(aUserInAServer -> {
|
||||
userExceptAuthorIds.add(aUserInAServer.getUserInServerId());
|
||||
});
|
||||
userExceptAuthor.forEach(aUserInAServer -> userExceptAuthorIds.add(aUserInAServer.getUserInServerId()));
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(STARBOARD_POST_TEMPLATE, starboardPostModel);
|
||||
PostTarget starboard = postTargetManagement.getPostTarget(StarboardPostTarget.STARBOARD.getKey(), message.getServerId());
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, StarboardPostTarget.STARBOARD, message.getServerId());
|
||||
Long starboardChannelId = starboard.getChannelReference().getId();
|
||||
Long starredUserId = starredUser.getUserInServerId();
|
||||
Long userReactingId = userReacting.getUserInServerId();
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
self.persistPost(message, userExceptAuthorIds, completableFutures, starboardChannelId, starredUserId, userReactingId);
|
||||
}) .exceptionally(throwable -> {
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
self.persistPost(message, userExceptAuthorIds, completableFutures, starboardChannelId, starredUserId, userReactingId)
|
||||
) .exceptionally(throwable -> {
|
||||
log.error("Failed to create starboard post for message {} in channel {} in server {}", message.getMessageId(), message.getChannelId(), message.getServerId(), throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CommandCreationListener {
|
||||
@EventListener
|
||||
@Transactional
|
||||
public void handleContextRefreshEvent(ContextRefreshedEvent ctxStartEvt) {
|
||||
featureFlagService.getAllFeatureConfigs().forEach((featureFlagKey) -> {
|
||||
featureFlagService.getAllFeatureConfigs().forEach(featureFlagKey -> {
|
||||
String featureKey = featureFlagKey.getFeature().getKey();
|
||||
if(!featureManagementService.featureExists(featureKey)) {
|
||||
featureManagementService.createFeature(featureKey);
|
||||
@@ -44,7 +44,7 @@ public class CommandCreationListener {
|
||||
log.warn("Command {} has null configuration.", command);
|
||||
return;
|
||||
}
|
||||
if(!commandService.doesCommandExist(command.getConfiguration().getName())) {
|
||||
if(commandService.doesCommandExist(command.getConfiguration().getName())) {
|
||||
commandService.createCommand(command.getConfiguration().getName(), command.getConfiguration().getModule(), command.getFeature());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CommandServiceBean implements CommandService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean doesCommandExist(String name) {
|
||||
public boolean doesCommandExist(String name) {
|
||||
return commandManagementService.doesCommandExist(name);
|
||||
}
|
||||
|
||||
@@ -66,9 +66,7 @@ public class CommandServiceBean implements CommandService {
|
||||
@Override
|
||||
public void allowFeatureForRole(FeatureEnum featureEnum, ARole role) {
|
||||
AFeature feature = featureManagementService.getFeature(featureEnum.getKey());
|
||||
feature.getCommands().forEach(command -> {
|
||||
this.allowCommandForRole(command, role);
|
||||
});
|
||||
feature.getCommands().forEach(command -> this.allowCommandForRole(command, role));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,9 +105,7 @@ public class CommandServiceBean implements CommandService {
|
||||
@Override
|
||||
public void disAllowFeatureForRole(FeatureEnum featureEnum, ARole role) {
|
||||
AFeature feature = featureManagementService.getFeature(featureEnum.getKey());
|
||||
feature.getCommands().forEach(command -> {
|
||||
this.disAllowCommandForRole(command, role);
|
||||
});
|
||||
feature.getCommands().forEach(command -> this.disAllowCommandForRole(command, role));
|
||||
}
|
||||
|
||||
public ConditionResult isCommandExecutable(Command command, CommandContext commandContext) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CommandManagementServiceBean implements CommandManagementService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean doesCommandExist(String name) {
|
||||
public boolean doesCommandExist(String name) {
|
||||
return findCommandByName(name) != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatures;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
@@ -11,12 +12,9 @@ import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatures;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -51,9 +51,9 @@ public class Disable extends AbstractConditionableCommand {
|
||||
FeatureConfig feature = featureConfigService.getFeatureDisplayForFeature(flagKey);
|
||||
featureFlagService.disableFeature(feature, commandContext.getGuild().getIdLong());
|
||||
if(feature.getDependantFeatures() != null) {
|
||||
feature.getDependantFeatures().forEach(featureDisplay -> {
|
||||
featureFlagService.disableFeature(featureDisplay, commandContext.getUserInitiatedContext().getServer());
|
||||
});
|
||||
feature.getDependantFeatures().forEach(featureDisplay ->
|
||||
featureFlagService.disableFeature(featureDisplay, commandContext.getUserInitiatedContext().getServer())
|
||||
);
|
||||
}
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Enable extends AbstractConditionableCommand {
|
||||
String flagKey = (String) commandContext.getParameters().getParameters().get(0);
|
||||
FeatureConfig feature = featureConfigService.getFeatureDisplayForFeature(flagKey);
|
||||
FeatureValidationResult featureSetup = featureConfigService.validateFeatureSetup(feature, commandContext.getUserInitiatedContext().getServer());
|
||||
if(!featureSetup.getValidationResult()) {
|
||||
if(Boolean.FALSE.equals(featureSetup.getValidationResult())) {
|
||||
channelService.sendTextToChannelNoFuture(templateService.renderTemplatable(featureSetup), commandContext.getChannel());
|
||||
}
|
||||
featureFlagService.enableFeature(feature, commandContext.getUserInitiatedContext().getServer());
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Help implements Command {
|
||||
ACommand aCommand = commandManagementService.findCommandByName(parameter);
|
||||
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getUserInitiatedContext().getServer());
|
||||
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
|
||||
if(aCommandInAServer.getRestricted()) {
|
||||
if(Boolean.TRUE.equals(aCommandInAServer.getRestricted())) {
|
||||
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
|
||||
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
|
||||
model.setRestricted(true);
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
|
||||
import com.jagrosh.jdautilities.menu.ButtonMenu;
|
||||
import dev.sheldan.abstracto.core.models.FullUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
@@ -14,16 +13,12 @@ import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
@@ -100,7 +95,7 @@ public class InteractiveServiceBean implements InteractiveService {
|
||||
|
||||
private void addEmoteToBuilder(String key, Consumer<Void> consumer, Long serverId, ButtonMenu.Builder builder, HashMap<String, Consumer<Void>> actions) {
|
||||
AEmote emoteOrFakeEmote = emoteService.getEmoteOrFakeEmote(key, serverId);
|
||||
if(emoteOrFakeEmote.getCustom()){
|
||||
if(Boolean.TRUE.equals(emoteOrFakeEmote.getCustom())){
|
||||
Optional<Emote> emote = botService.getEmote(serverId, emoteOrFakeEmote);
|
||||
emote.ifPresent(emote1 -> {
|
||||
builder.addChoice(emote1);
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FeatureFlagListener implements ServerConfigListener {
|
||||
@Override
|
||||
public void updateServerConfig(AServer server) {
|
||||
log.info("Setting up feature flags if necessary.");
|
||||
featureFlagService.getAllFeatureConfigs().forEach((featureFlagKey) -> {
|
||||
featureFlagService.getAllFeatureConfigs().forEach(featureFlagKey -> {
|
||||
String featureKey = featureFlagKey.getFeature().getKey();
|
||||
AFeature feature = featureManagementService.getFeature(featureKey);
|
||||
if(featureConfigLoader.getFeatures().containsKey(featureKey)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ReactionUpdatedListener extends ListenerAdapter {
|
||||
private List<ReactionClearedListener> clearedListenerList;
|
||||
|
||||
@Autowired
|
||||
private List<ReactedRemovedListener> reactionRemovedListener;
|
||||
private List<ReactedRemovedListener> reactionRemovedListeners;
|
||||
|
||||
@Autowired
|
||||
private ReactionUpdatedListener self;
|
||||
@@ -63,15 +63,15 @@ public class ReactionUpdatedListener extends ListenerAdapter {
|
||||
return;
|
||||
}
|
||||
CompletableFuture<CachedMessage> asyncMessageFromCache = messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong());
|
||||
asyncMessageFromCache.thenAccept(cachedMessage -> {
|
||||
asyncMessageFromCache.thenAccept(cachedMessage ->
|
||||
messageCache.getCachedReactionFromReaction(event.getReaction()).thenAccept(reaction -> {
|
||||
self.callAddedListeners(event, cachedMessage, reaction);
|
||||
messageCache.putMessageInCache(cachedMessage);
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Failed to add reaction to message {} ", event.getMessageIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}).exceptionally(throwable -> {
|
||||
})
|
||||
).exceptionally(throwable -> {
|
||||
log.error("Message retrieval {} from cache failed. ", event.getMessageIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
@@ -146,7 +146,7 @@ public class ReactionUpdatedListener extends ListenerAdapter {
|
||||
public void callRemoveListeners(@Nonnull GuildMessageReactionRemoveEvent event, CachedMessage cachedMessage, CachedReaction reaction) {
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadUser(event.getGuild().getIdLong(), event.getUserIdLong());
|
||||
removeReactionIfThere(cachedMessage, reaction, userInAServer);
|
||||
reactionRemovedListener.forEach(reactionRemovedListener -> {
|
||||
reactionRemovedListeners.forEach(reactionRemovedListener -> {
|
||||
FeatureConfig feature = featureConfigService.getFeatureDisplayForFeature(reactionRemovedListener.getFeature());
|
||||
if(!featureFlagService.isFeatureEnabled(feature, event.getGuild().getIdLong())) {
|
||||
return;
|
||||
|
||||
@@ -131,7 +131,7 @@ public class BotServiceBean implements BotService {
|
||||
|
||||
@Override
|
||||
public Optional<Emote> getEmote(Long serverId, AEmote emote) {
|
||||
if(!emote.getCustom()) {
|
||||
if(Boolean.FALSE.equals(emote.getCustom())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Optional<Guild> guildById = getGuildById(serverId);
|
||||
|
||||
@@ -21,9 +21,6 @@ import java.util.Optional;
|
||||
@Component
|
||||
public class ChannelGroupServiceBean implements ChannelGroupService {
|
||||
|
||||
private static final String CHANNEL_GROUP_NOT_FOUND = "Channel group %s was not found.";
|
||||
private static final String COMMAND_NOT_FOUND = "Command %s not found.";
|
||||
|
||||
@Autowired
|
||||
private ChannelGroupManagementService channelGroupManagementService;
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ public class DelayedActionServiceBean implements DelayedActionService {
|
||||
|
||||
@Override
|
||||
public void executeDelayedActions(List<DelayedActionConfig> delayedActionConfigList) {
|
||||
delayedActionConfigList.forEach(delayedActionConfig -> {
|
||||
delayedActionConfigList.forEach(delayedActionConfig ->
|
||||
delayedActions.stream()
|
||||
.filter(delayedAction -> delayedAction.handles(delayedActionConfig))
|
||||
.findFirst()
|
||||
.ifPresent(delayedAction -> delayedAction.execute(delayedActionConfig));
|
||||
});
|
||||
.ifPresent(delayedAction -> delayedAction.execute(delayedActionConfig))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ public class FeatureConfigServiceBean implements FeatureConfigService {
|
||||
Predicate<PostTargetEnum> postTargetComparison = postTargetEnum -> postTargetEnum.getKey().equalsIgnoreCase(key);
|
||||
Optional<FeatureConfig> foundFeature = availableFeatures.stream().filter(featureDisplay -> featureDisplay.getRequiredPostTargets().stream().anyMatch(postTargetComparison)).findAny();
|
||||
if(foundFeature.isPresent()) {
|
||||
return foundFeature.get().getRequiredPostTargets().stream().filter(postTargetComparison).findAny().get();
|
||||
Optional<PostTargetEnum> any = foundFeature.get().getRequiredPostTargets().stream().filter(postTargetComparison).findAny();
|
||||
return any.orElse(null);
|
||||
}
|
||||
throw new AbstractoRunTimeException(String.format("Post target %s not found.", key));
|
||||
}
|
||||
@@ -99,18 +100,18 @@ public class FeatureConfigServiceBean implements FeatureConfigService {
|
||||
@Override
|
||||
public FeatureValidationResult validateFeatureSetup(FeatureConfig featureConfig, AServer server) {
|
||||
FeatureValidationResult featureValidationResult = FeatureValidationResult.validationSuccessful(featureConfig);
|
||||
featureConfig.getRequiredPostTargets().forEach(s -> {
|
||||
featureValidatorService.checkPostTarget(s, server, featureValidationResult);
|
||||
});
|
||||
featureConfig.getRequiredSystemConfigKeys().forEach(s -> {
|
||||
featureValidatorService.checkSystemConfig(s, server, featureValidationResult);
|
||||
});
|
||||
featureConfig.getRequiredEmotes().forEach(s -> {
|
||||
featureValidatorService.checkEmote(s, server, featureValidationResult);
|
||||
});
|
||||
featureConfig.getAdditionalFeatureValidators().forEach(featureValidator -> {
|
||||
featureValidator.featureIsSetup(featureConfig, server, featureValidationResult);
|
||||
});
|
||||
featureConfig.getRequiredPostTargets().forEach(s ->
|
||||
featureValidatorService.checkPostTarget(s, server, featureValidationResult)
|
||||
);
|
||||
featureConfig.getRequiredSystemConfigKeys().forEach(s ->
|
||||
featureValidatorService.checkSystemConfig(s, server, featureValidationResult)
|
||||
);
|
||||
featureConfig.getRequiredEmotes().forEach(s ->
|
||||
featureValidatorService.checkEmote(s, server, featureValidationResult)
|
||||
);
|
||||
featureConfig.getAdditionalFeatureValidators().forEach(featureValidator ->
|
||||
featureValidator.featureIsSetup(featureConfig, server, featureValidationResult)
|
||||
);
|
||||
return featureValidationResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ package dev.sheldan.abstracto.core.service;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.FeatureNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.FeatureValidationResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeatureFlag;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
@@ -15,11 +12,6 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class FeatureFlagServiceBean implements FeatureFlagService {
|
||||
|
||||
|
||||
@@ -88,15 +88,15 @@ public class MessageCacheBean implements MessageCache {
|
||||
if(textChannelByIdOptional.isPresent()) {
|
||||
TextChannel textChannel = textChannelByIdOptional.get();
|
||||
textChannel.retrieveMessageById(messageId).queue(message ->
|
||||
{
|
||||
|
||||
buildCachedMessageFromMessage(message)
|
||||
.thenAccept(future::complete)
|
||||
.exceptionally(throwable -> {
|
||||
log.error("Failed to load message for caching.", throwable);
|
||||
future.completeExceptionally(throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
);
|
||||
} else {
|
||||
log.error("Not able to load message {} in channel {} in guild {}. Text channel not found.", messageId, textChannelId, guildId);
|
||||
@@ -123,9 +123,7 @@ public class MessageCacheBean implements MessageCache {
|
||||
);
|
||||
|
||||
List<CompletableFuture<CachedReaction>> futures = new ArrayList<>();
|
||||
message.getReactions().forEach(messageReaction -> {
|
||||
futures.add(self.getCachedReactionFromReaction(messageReaction));
|
||||
});
|
||||
message.getReactions().forEach(messageReaction -> futures.add(self.getCachedReactionFromReaction(messageReaction)));
|
||||
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
future.complete(CachedMessage.builder()
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MessageServiceBean implements MessageService {
|
||||
AEmote emote = emoteService.getEmoteOrFakeEmote(emoteKey, serverId);
|
||||
if(guildByIdOptional.isPresent()) {
|
||||
Guild guild = guildByIdOptional.get();
|
||||
if(emote.getCustom()) {
|
||||
if(Boolean.TRUE.equals(emote.getCustom())) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emote.getEmoteId());
|
||||
if(emoteById != null) {
|
||||
return message.addReaction(emoteById).submit();
|
||||
@@ -68,9 +68,7 @@ public class MessageServiceBean implements MessageService {
|
||||
@Override
|
||||
public List<CompletableFuture<Void>> addReactionsToMessageWithFuture(List<String> emoteKeys, Long serverId, Message message) {
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
emoteKeys.forEach(s -> {
|
||||
futures.add(addReactionToMessageWithFuture(s, serverId, message));
|
||||
});
|
||||
emoteKeys.forEach(s -> futures.add(addReactionToMessageWithFuture(s, serverId, message)));
|
||||
return futures;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,7 @@ public class PaginatorServiceBean implements PaginatorService {
|
||||
.setEventWaiter(waiter)
|
||||
.waitOnSinglePage(true)
|
||||
.setTimeout(ObjectUtils.defaultIfNull(configuration.getTimeoutSeconds(), 120L), TimeUnit.SECONDS)
|
||||
.setFinalAction(message -> {
|
||||
message.delete().queue();
|
||||
})
|
||||
.setFinalAction(message -> message.delete().queue())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -137,9 +137,7 @@ public class SetupServiceBean implements SetupService {
|
||||
.delayedActionList(delayedActionConfigs)
|
||||
.previousMessageId(initialMessage)
|
||||
.build();
|
||||
setupSummaryStep.execute(user, parameter).thenAccept(ignored -> {
|
||||
self.notifyAboutCompletion(user, featureConfig);
|
||||
});
|
||||
setupSummaryStep.execute(user, parameter).thenAccept(ignored -> self.notifyAboutCompletion(user, featureConfig));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -23,26 +23,24 @@ public class UndoActionServiceBean implements UndoActionService {
|
||||
actionsToPerform.forEach(undoActionInstance -> {
|
||||
UndoAction action = undoActionInstance.getAction();
|
||||
List<Long> ids = undoActionInstance.getIds();
|
||||
switch (action) {
|
||||
case DELETE_CHANNEL:
|
||||
if(ids.size() != 2) {
|
||||
log.error("Not the correct amount of ids provided for the channel deletion undo action.");
|
||||
break;
|
||||
}
|
||||
deleteChannel(ids.get(0), ids.get(1));
|
||||
break;
|
||||
case DELETE_MESSAGE:
|
||||
if(ids.size() != 2) {
|
||||
log.error("Not the correct amount of ids provided for the message deletion undo action.");
|
||||
break;
|
||||
}
|
||||
botService.deleteMessage(ids.get(0), ids.get(1));
|
||||
if(action.equals(UndoAction.DELETE_CHANNEL)) {
|
||||
if(ids.size() != 2) {
|
||||
log.error("Not the correct amount of ids provided for the channel deletion undo action.");
|
||||
return;
|
||||
}
|
||||
deleteChannel(ids.get(0), ids.get(1));
|
||||
} else if(action.equals(UndoAction.DELETE_MESSAGE)) {
|
||||
if(ids.size() != 2) {
|
||||
log.error("Not the correct amount of ids provided for the message deletion undo action.");
|
||||
return;
|
||||
}
|
||||
botService.deleteMessage(ids.get(0), ids.get(1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteChannel(Long serverId, Long channelId) {
|
||||
channelService.deleteTextChannel(serverId, channelId).exceptionally((throwable) -> {
|
||||
channelService.deleteTextChannel(serverId, channelId).exceptionally(throwable -> {
|
||||
log.error("Failed to execute undo action channel delete for channel {} in server {}", channelId, serverId, throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class FeatureFlagManagementServiceBean implements FeatureFlagManagementService {
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PostTargetManagementBean implements PostTargetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean postTargetExists(String name, Long serverId) {
|
||||
public boolean postTargetExists(String name, Long serverId) {
|
||||
AServer dbServer = serverManagementService.loadOrCreate(serverId);
|
||||
return postTargetExists(name, dbServer);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAware;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Command extends FeatureAware {
|
||||
|
||||
CommandResult execute(CommandContext commandContext);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CommandDisallowedCondition implements CommandCondition {
|
||||
public ConditionResult shouldExecute(CommandContext context, Command command) {
|
||||
ACommand aCommand = commandService.findCommandByName(command.getConfiguration().getName());
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, context.getUserInitiatedContext().getServer());
|
||||
if(!commandForServer.getRestricted()) {
|
||||
if(Boolean.FALSE.equals(commandForServer.getRestricted())) {
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
for (ARole role : commandForServer.getAllowedRoles()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.execution;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -30,6 +31,6 @@ public class ContextConverter {
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
}
|
||||
throw new RuntimeException("Failed to create model from context");
|
||||
throw new AbstractoRunTimeException("Failed to create model from context");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@@ -15,7 +16,7 @@ import java.util.Objects;
|
||||
@Getter
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ACommand {
|
||||
public class ACommand implements Serializable {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -17,7 +18,7 @@ import java.util.Objects;
|
||||
@NoArgsConstructor
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ACommandInAServer {
|
||||
public class ACommandInAServer implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -19,7 +20,7 @@ import java.util.Objects;
|
||||
@Getter
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class AModule {
|
||||
public class AModule implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
|
||||
public interface CommandService {
|
||||
ACommand createCommand(String name, String moduleName, FeatureEnum featureEnum);
|
||||
Boolean doesCommandExist(String name);
|
||||
boolean doesCommandExist(String name);
|
||||
void allowCommandForRole(ACommand aCommand, ARole role);
|
||||
void allowFeatureForRole(FeatureEnum featureEnum, ARole role);
|
||||
void makeRoleImmuneForCommand(ACommand aCommand, ARole role);
|
||||
|
||||
@@ -8,5 +8,5 @@ public interface CommandManagementService {
|
||||
ACommand createCommand(String name, String moduleName, String featureName);
|
||||
ACommand createCommand(String name, AModule moduleName, AFeature feature);
|
||||
ACommand findCommandByName(String name);
|
||||
Boolean doesCommandExist(String name);
|
||||
boolean doesCommandExist(String name);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class CategoryNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long categoryId;
|
||||
private Long guildId;
|
||||
|
||||
public CategoryNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
private final Long categoryId;
|
||||
private final Long guildId;
|
||||
|
||||
public CategoryNotFoundException(Long categoryId, Long guildId) {
|
||||
super("");
|
||||
|
||||
@@ -6,12 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class ChannelNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long channelId;
|
||||
private Long guildId;
|
||||
|
||||
public ChannelNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
private final Long channelId;
|
||||
private final Long guildId;
|
||||
|
||||
public ChannelNotFoundException(Long channelId, Long guildId) {
|
||||
super("");
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
public class ConfigurationKeyNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String key;
|
||||
private final String key;
|
||||
|
||||
public ConfigurationKeyNotFoundException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class DurationFormatException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String invalidFormat;
|
||||
private List<String> validFormats;
|
||||
private final String invalidFormat;
|
||||
private final List<String> validFormats;
|
||||
|
||||
public DurationFormatException(String wrongFormat, List<String> validFormats) {
|
||||
super("");
|
||||
|
||||
@@ -3,11 +3,10 @@ package dev.sheldan.abstracto.core.exception;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EmoteNotDefinedException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String emoteKey;
|
||||
private final String emoteKey;
|
||||
|
||||
public EmoteNotDefinedException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class EmoteNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String emoteKey;
|
||||
private List<String> available;
|
||||
private final String emoteKey;
|
||||
private final List<String> available;
|
||||
|
||||
public EmoteNotFoundException(String key, List<String> availableEmotes) {
|
||||
super("");
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.templating.Templatable;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GuildException extends AbstractoRunTimeException implements Templatable {
|
||||
private Long guildId;
|
||||
private final Long guildId;
|
||||
|
||||
public GuildException(String message, Long guildId) {
|
||||
super(message);
|
||||
|
||||
@@ -3,11 +3,10 @@ package dev.sheldan.abstracto.core.exception;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class PostTargetNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String postTargetKey;
|
||||
private final String postTargetKey;
|
||||
|
||||
public PostTargetNotFoundException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class PostTargetNotValidException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String postTargetKey;
|
||||
private List<String> availableTargets;
|
||||
private final String postTargetKey;
|
||||
private final List<String> availableTargets;
|
||||
|
||||
public PostTargetNotValidException(String key, List<String> available) {
|
||||
super("");
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInDBException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long roleId;
|
||||
private Long serverId;
|
||||
private final Long roleId;
|
||||
private final Long serverId;
|
||||
|
||||
public RoleNotFoundInDBException(Long roleId, Long serverId) {
|
||||
super("");
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInGuildException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long roleId;
|
||||
private Long serverId;
|
||||
private final Long roleId;
|
||||
private final Long serverId;
|
||||
|
||||
public RoleNotFoundInGuildException(Long roleId, Long serverId) {
|
||||
super("");
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
public class UserInServerNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long userInServerId;
|
||||
private final Long userInServerId;
|
||||
|
||||
public UserInServerNotFoundException(Long userInServerId) {
|
||||
super("");
|
||||
|
||||
@@ -27,9 +27,7 @@ public abstract class AbstractConfigSetupStep implements SetupStep {
|
||||
|
||||
|
||||
protected Runnable getTimeoutRunnable(Long serverId, Long channelId) {
|
||||
return () -> {
|
||||
interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
};
|
||||
return () -> interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
}
|
||||
|
||||
protected boolean checkForExit(Message message) {
|
||||
|
||||
@@ -22,8 +22,6 @@ public class InteractiveUtils {
|
||||
public void sendTimeoutMessage(Long serverId, Long channelId) {
|
||||
String s = templateService.renderSimpleTemplate("setup_configuration_timeout");
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelInGuild(serverId, channelId);
|
||||
channelOptional.ifPresent(channel -> {
|
||||
channelService.sendTextToChannelNoFuture(s, channel);
|
||||
});
|
||||
channelOptional.ifPresent(channel -> channelService.sendTextToChannelNoFuture(s, channel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package dev.sheldan.abstracto.core.models;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,7 +5,6 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.core.models.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.SnowFlake;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AConfig implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
@@ -75,7 +75,7 @@ public class AConfig implements Serializable {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AConfig config = (AConfig) o;
|
||||
return Objects.equals(Id, config.Id) &&
|
||||
return Objects.equals(id, config.id) &&
|
||||
Objects.equals(name, config.name) &&
|
||||
Objects.equals(stringValue, config.stringValue) &&
|
||||
Objects.equals(doubleValue, config.doubleValue) &&
|
||||
@@ -84,6 +84,6 @@ public class AConfig implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Id, name, stringValue, doubleValue, server);
|
||||
return Objects.hash(id, name, stringValue, doubleValue, server);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.time.Instant;
|
||||
public class ADefaultConfig implements Serializable {
|
||||
@javax.persistence.Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AEmote implements Serializable {
|
||||
|
||||
@javax.persistence.Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
@@ -66,7 +66,7 @@ public class AEmote implements Serializable {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AEmote emote = (AEmote) o;
|
||||
return Objects.equals(Id, emote.Id) &&
|
||||
return Objects.equals(id, emote.id) &&
|
||||
Objects.equals(name, emote.name) &&
|
||||
Objects.equals(emoteKey, emote.emoteKey) &&
|
||||
Objects.equals(emoteId, emote.emoteId) &&
|
||||
@@ -77,6 +77,6 @@ public class AEmote implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Id, name, emoteKey, emoteId, animated, custom, serverRef);
|
||||
return Objects.hash(id, name, emoteKey, emoteId, animated, custom, serverRef);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands.help;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.SingleLevelPackedModule;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -5,7 +5,6 @@ import dev.sheldan.abstracto.core.models.cache.CachedReaction;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface MessageCache {
|
||||
|
||||
@@ -12,6 +12,6 @@ public interface PostTargetManagement {
|
||||
PostTarget getPostTarget(String name, AServer server);
|
||||
PostTarget getPostTarget(String name, Long serverId);
|
||||
Boolean postTargetExists(String name, AServer server);
|
||||
Boolean postTargetExists(String name, Long serverId);
|
||||
boolean postTargetExists(String name, Long serverId);
|
||||
PostTarget updatePostTarget(PostTarget target, AServer server, AChannel newTargetChannel);
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class EmoteUtils {
|
||||
}
|
||||
|
||||
public static boolean compareAEmote(AEmote a, AEmote b) {
|
||||
if(a.getCustom() && b.getCustom()) {
|
||||
if(Boolean.TRUE.equals(a.getCustom()) && Boolean.TRUE.equals(b.getCustom())) {
|
||||
return a.getEmoteId().equals(b.getEmoteId());
|
||||
} else {
|
||||
if(!a.getCustom() && !b.getCustom()) {
|
||||
if(Boolean.FALSE.equals(a.getCustom()) && Boolean.FALSE.equals(b.getCustom())) {
|
||||
return a.getEmoteKey().equals(b.getEmoteKey());
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.quartz.*;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -24,9 +23,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
|
||||
import static org.quartz.TriggerBuilder.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SchedulerServiceBeanTest {
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package dev.sheldan.abstracto.templating.service;
|
||||
import com.google.gson.Gson;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.templating.model.*;
|
||||
import dev.sheldan.abstracto.templating.model.database.Template;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -61,8 +60,8 @@ public class TemplateServiceBean implements TemplateService {
|
||||
String embedConfig = this.renderTemplate(key + "_embed", model);
|
||||
List<EmbedBuilder> embedBuilders = new ArrayList<>();
|
||||
embedBuilders.add(new EmbedBuilder());
|
||||
EmbedConfiguration configuration = gson.fromJson(embedConfig, EmbedConfiguration.class);
|
||||
String description = configuration.getDescription();
|
||||
EmbedConfiguration embedConfiguration = gson.fromJson(embedConfig, EmbedConfiguration.class);
|
||||
String description = embedConfiguration.getDescription();
|
||||
if(description != null) {
|
||||
double neededIndices = Math.ceil(description.length() / (double) MessageEmbed.TEXT_MAX_LENGTH) - 1;
|
||||
extendIfNecessary(embedBuilders, neededIndices);
|
||||
@@ -71,32 +70,32 @@ public class TemplateServiceBean implements TemplateService {
|
||||
embedBuilders.get(i).setDescription(descriptionText);
|
||||
}
|
||||
}
|
||||
EmbedAuthor author = configuration.getAuthor();
|
||||
EmbedAuthor author = embedConfiguration.getAuthor();
|
||||
EmbedBuilder firstBuilder = embedBuilders.get(0);
|
||||
if(author != null) {
|
||||
firstBuilder.setAuthor(author.getName(), author.getUrl(), author.getAvatar());
|
||||
}
|
||||
|
||||
String thumbnail = configuration.getThumbnail();
|
||||
String thumbnail = embedConfiguration.getThumbnail();
|
||||
if(thumbnail != null) {
|
||||
firstBuilder.setThumbnail(thumbnail);
|
||||
}
|
||||
EmbedTitle title = configuration.getTitle();
|
||||
EmbedTitle title = embedConfiguration.getTitle();
|
||||
if(title != null) {
|
||||
firstBuilder.setTitle(title.getTitle(), title.getUrl());
|
||||
}
|
||||
EmbedFooter footer = configuration.getFooter();
|
||||
EmbedFooter footer = embedConfiguration.getFooter();
|
||||
if(footer != null) {
|
||||
firstBuilder.setFooter(footer.getText(), footer.getIcon());
|
||||
}
|
||||
if(configuration.getFields() != null) {
|
||||
createFieldsForEmbed(key, embedBuilders, configuration);
|
||||
if(embedConfiguration.getFields() != null) {
|
||||
createFieldsForEmbed(key, embedBuilders, embedConfiguration);
|
||||
}
|
||||
firstBuilder.setTimestamp(configuration.getTimeStamp());
|
||||
firstBuilder.setTimestamp(embedConfiguration.getTimeStamp());
|
||||
|
||||
firstBuilder.setImage(configuration.getImageUrl());
|
||||
firstBuilder.setImage(embedConfiguration.getImageUrl());
|
||||
|
||||
EmbedColor color = configuration.getColor();
|
||||
EmbedColor color = embedConfiguration.getColor();
|
||||
if(color != null) {
|
||||
int colorToSet = new Color(color.getR(), color.getG(), color.getB()).getRGB();
|
||||
embedBuilders.forEach(embedBuilder -> embedBuilder.setColor(colorToSet));
|
||||
@@ -109,7 +108,7 @@ public class TemplateServiceBean implements TemplateService {
|
||||
|
||||
return MessageToSend.builder()
|
||||
.embeds(embeds)
|
||||
.message(configuration.getAdditionalMessage())
|
||||
.message(embedConfiguration.getAdditionalMessage())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ public class TemplateServiceBean implements TemplateService {
|
||||
for (int i = 0; i < configuration.getFields().size(); i++) {
|
||||
double currentPart = Math.floor(i / 25D);
|
||||
EmbedField embedField = configuration.getFields().get(i);
|
||||
Boolean inline = embedField.getInline() != null ? embedField.getInline() : Boolean.FALSE;
|
||||
boolean inline = embedField.getInline() != null ? embedField.getInline() : Boolean.FALSE;
|
||||
embedBuilders.get((int) currentPart).addField(embedField.getName(), embedField.getValue(), inline);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user