mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-27 23:09:05 +00:00
fixed some code smells
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.utility.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
@@ -7,7 +8,6 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.ShowEmoteLog;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -47,7 +47,7 @@ public class ShowEmote extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("showEmote")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.utility.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.starboard.StarStatsModel;
|
||||
import dev.sheldan.abstracto.utility.service.StarboardService;
|
||||
@@ -48,7 +48,7 @@ public class StarStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("starStats")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.utility.commands.remind;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
@@ -8,7 +9,6 @@ import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ReminderModel;
|
||||
import dev.sheldan.abstracto.utility.service.ReminderService;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
@@ -46,7 +46,7 @@ public class Remind extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("remind")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.utility.commands.remind;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.RemindersModel;
|
||||
@@ -47,7 +47,7 @@ public class Reminders extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().longHelp("Shows the current active reminders").usage("reminders").build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("reminders")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.description("Shows the current active reminders")
|
||||
.causesReaction(true)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package dev.sheldan.abstracto.utility.commands.suggest;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -41,7 +41,7 @@ public class Accept extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("accept")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package dev.sheldan.abstracto.utility.commands.suggest;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -41,7 +41,7 @@ public class Reject extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("reject")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package dev.sheldan.abstracto.utility.commands.suggest;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.utility.config.Utility;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -40,7 +40,7 @@ public class Suggest extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("suggest")
|
||||
.module(Utility.UTILITY)
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.utility.listener.embed;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.MessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.MessageCache;
|
||||
import dev.sheldan.abstracto.core.service.management.UserManagementService;
|
||||
@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -38,11 +40,10 @@ public class MessageEmbedListener implements MessageReceivedListener {
|
||||
for (MessageEmbedLink messageEmbedLink : links) {
|
||||
messageRaw = messageRaw.replace(messageEmbedLink.getWholeUrl(), "");
|
||||
AUserInAServer cause = userManagementService.loadUser(message.getMember());
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessage -> {
|
||||
messageEmbedService.embedLink(cachedMessage, message.getTextChannel(), cause, message);
|
||||
});
|
||||
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage -> messageEmbedService.embedLink(cachedMessage, message.getTextChannel(), cause, message);
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessageConsumer);
|
||||
}
|
||||
if(StringUtils.isBlank(messageRaw) && links.size() > 0) {
|
||||
if(StringUtils.isBlank(messageRaw) && !links.isEmpty()) {
|
||||
message.delete().queue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ public class MessageEmbedRemovalReactionListener implements ReactedAddedListener
|
||||
if(embeddedMessage.getEmbeddedUser().getUserReference().getId().equals(userReacting.getId())
|
||||
|| embeddedMessage.getEmbeddingUser().getUserReference().getId().equals(userReacting.getId())
|
||||
) {
|
||||
messageService.deleteMessageInChannelInServer(message.getServerId(), message.getChannelId(), message.getMessageId()).thenAccept(aVoid -> {
|
||||
messageEmbedPostManagementService.deleteEmbeddedMessageTransactional(embeddedMessage);
|
||||
});
|
||||
messageService.deleteMessageInChannelInServer(message.getServerId(), message.getChannelId(), message.getMessageId()).thenAccept(aVoid ->
|
||||
messageEmbedPostManagementService.deleteEmbeddedMessageTransactional(embeddedMessage)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -37,7 +38,7 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
|
||||
|
||||
private Pattern messageRegex = Pattern.compile("(?<whole>https://discordapp.com/channels/(?<server>\\d+)/(?<channel>\\d+)/(?<message>\\d+)(?:.*?))+");
|
||||
|
||||
public static final String MESSAGE_EMBED_TEMPLATE = "message";
|
||||
public static final String MESSAGE_EMBED_TEMPLATE = "message_embed";
|
||||
public static final String REMOVAL_EMOTE = "removeEmbed";
|
||||
|
||||
@Autowired
|
||||
@@ -96,12 +97,12 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
|
||||
|
||||
@Override
|
||||
public void embedLinks(List<MessageEmbedLink> linksToEmbed, TextChannel target, AUserInAServer reason, Message embeddingMessage) {
|
||||
linksToEmbed.forEach(messageEmbedLink -> {
|
||||
linksToEmbed.forEach(messageEmbedLink ->
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId())
|
||||
.thenAccept(cachedMessage -> {
|
||||
self.embedLink(cachedMessage, target, reason, embeddingMessage);
|
||||
});
|
||||
});
|
||||
.thenAccept(cachedMessage ->
|
||||
self.embedLink(cachedMessage, target, reason, embeddingMessage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +130,11 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
|
||||
AServer server = serverManagementService.loadOrCreate(message.getGuild().getIdLong());
|
||||
AUserInAServer user = userManagementService.loadUser(message.getMember());
|
||||
Member author = botService.getMemberInServer(embeddedMessage.getServerId(), embeddedMessage.getAuthorId());
|
||||
TextChannel sourceChannel = botService.getTextChannelFromServer(embeddedMessage.getServerId(), embeddedMessage.getChannelId()).get();
|
||||
Optional<TextChannel> textChannelFromServer = botService.getTextChannelFromServer(embeddedMessage.getServerId(), embeddedMessage.getChannelId());
|
||||
TextChannel sourceChannel = null;
|
||||
if(textChannelFromServer.isPresent()) {
|
||||
sourceChannel = textChannelFromServer.get();
|
||||
}
|
||||
return MessageEmbeddedModel
|
||||
.builder()
|
||||
.channel(channel)
|
||||
|
||||
@@ -81,10 +81,9 @@ public class StarboardServiceBean implements StarboardService {
|
||||
.server(userReacting.getServerReference())
|
||||
.build();
|
||||
StarboardPost starboardPost = starboardPostManagementService.createStarboardPost(message, starredUser, userReacting, aServerAChannelMessage);
|
||||
// TODO maybe in bulk, but numbers should be small enough
|
||||
userExceptAuthor.forEach(user -> {
|
||||
starboardPostReactorManagementService.addReactor(starboardPost, user);
|
||||
});
|
||||
userExceptAuthor.forEach(user ->
|
||||
starboardPostReactorManagementService.addReactor(starboardPost, user)
|
||||
);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("Failed to post messages.", e);
|
||||
}
|
||||
@@ -117,9 +116,9 @@ public class StarboardServiceBean implements StarboardService {
|
||||
@Override
|
||||
public void updateStarboardPost(StarboardPost post, CachedMessage message, List<AUser> userExceptAuthor) {
|
||||
StarboardPostModel starboardPostModel = buildStarboardPostModel(message, userExceptAuthor.size());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("starboard_post", starboardPostModel);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(STARBOARD_POST_TEMPLATE, starboardPostModel);
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
postTargetService.editOrCreatedInPostTarget(post.getStarboardMessageId(), messageToSend, "starboard", message.getServerId(), futures);
|
||||
postTargetService.editOrCreatedInPostTarget(post.getStarboardMessageId(), messageToSend, STARBOARD_POSTTARGET, message.getServerId(), futures);
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
try {
|
||||
starboardPostManagementService.setStarboardPostMessageId(post, futures.get(0).get().getIdLong());
|
||||
|
||||
@@ -102,9 +102,9 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
suggestionLog.setSuggestion(suggestion);
|
||||
TextChannel textChannelById = guildById.getTextChannelById(channelId);
|
||||
if(textChannelById != null) {
|
||||
textChannelById.retrieveMessageById(originalMessageId).queue(message -> {
|
||||
self.updateSuggestionMessageText(text, suggestionLog, message);
|
||||
});
|
||||
textChannelById.retrieveMessageById(originalMessageId).queue(message ->
|
||||
self.updateSuggestionMessageText(text, suggestionLog, message)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user