fixed some code smells

This commit is contained in:
Sheldan
2020-04-27 20:23:02 +02:00
parent e08086b6a9
commit 8e7bc7d98f
91 changed files with 251 additions and 268 deletions

View File

@@ -12,7 +12,6 @@ import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
import dev.sheldan.abstracto.core.Constants;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
@@ -152,7 +151,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
public Parameters getParsedParameters(UnParsedCommandParameter unParsedCommandParameter, Command command, Message message){
List<Object> parsedParameters = new ArrayList<>();
if(command.getConfiguration().getParameters() == null || command.getConfiguration().getParameters().size() == 0) {
if(command.getConfiguration().getParameters() == null || command.getConfiguration().getParameters().isEmpty()) {
return Parameters.builder().parameters(parsedParameters).build();
}
Iterator<TextChannel> channelIterator = message.getMentionedChannels().iterator();
@@ -199,7 +198,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
if(!reminderActive) {
parsedParameters.add(value);
} else {
if(parsedParameters.size() == 0) {
if(parsedParameters.isEmpty()) {
parsedParameters.add(value);
} else {
int lastIndex = parsedParameters.size() - 1;

View File

@@ -25,10 +25,8 @@ public class ReactionPostExecution implements PostCommandExecution {
if(commandResult.getMessage() != null && commandResult.getThrowable() == null){
commandContext.getChannel().sendMessage(commandResult.getMessage()).queue();
}
} else if(result.equals(ResultState.SUCCESSFUL)) {
if(command.getConfiguration().isCausesReaction()){
messageService.addReactionToMessage(SUCCESS_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
}
} else if(result.equals(ResultState.SUCCESSFUL) && command.getConfiguration().isCausesReaction()) {
messageService.addReactionToMessage(SUCCESS_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
}
}

View File

@@ -22,15 +22,10 @@ public class ChannelGroupCommandServiceBean implements ChannelGroupCommandServic
for (AChannelGroupCommand aChannelGroupCommand : allChannelGroupsOfCommand) {
Optional<AChannel> channelInGroup = aChannelGroupCommand.getGroup()
.getChannels().stream().filter(channel1 -> channel1.getId().equals(channel.getId())).findAny();
if (channelInGroup.isPresent()) {
if (aChannelGroupCommand.getEnabled()) {
return true;
}
if (channelInGroup.isPresent() && aChannelGroupCommand.getEnabled()) {
return true;
}
}
if(allChannelGroupsOfCommand.size() == 0) {
return true;
}
return false;
return allChannelGroupsOfCommand.isEmpty();
}
}

View File

@@ -46,7 +46,7 @@ public class CommandManager implements CommandRegistry {
}
parameterFit = paramCountFits || hasRemainderParameter;
} else {
parameterFit = unParsedCommandParameter.getParameters().size() == 0;
parameterFit = unParsedCommandParameter.getParameters().isEmpty();
}
return parameterFit;
}).findFirst();
@@ -86,13 +86,13 @@ public class CommandManager implements CommandRegistry {
@Override
public List<Command> getAllCommandsFromModule(ModuleInterface moduleInterface) {
List<Command> commands = new ArrayList<>();
List<Command> commandsFromModule = new ArrayList<>();
this.getAllCommands().forEach(command -> {
if(command.getConfiguration().getModule().equals(moduleInterface.getInfo().getName())){
commands.add(command);
commandsFromModule.add(command);
}
});
return commands;
return commandsFromModule;
}
@Override

View File

@@ -4,8 +4,6 @@ import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.config.CommandHierarchy;
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
import dev.sheldan.abstracto.core.command.config.PackedModule;
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@@ -40,9 +40,9 @@ public class Allow extends AbstractConditionableCommand {
String name = (String) commandContext.getParameters().getParameters().get(0);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer());
});
feature.getCommands().forEach(command ->
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer())
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer());

View File

@@ -43,9 +43,9 @@ public class AllowRole extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.allowCommandForRole(command, role);
});
feature.getCommands().forEach(command ->
commandService.allowCommandForRole(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.allowCommandForRole(command, role);

View File

@@ -43,9 +43,9 @@ public class DisAllowRole extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.disAllowCommandForRole(command, role);
});
feature.getCommands().forEach(command ->
commandService.disAllowCommandForRole(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.disAllowCommandForRole(command, role);

View File

@@ -35,7 +35,7 @@ public class Disable extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
if(commandContext.getParameters().getParameters().size() == 0) {
if(commandContext.getParameters().getParameters().isEmpty()) {
EnableModel model = (EnableModel) ContextConverter.fromCommandContext(commandContext, EnableModel.class);
model.setFeatures(featureFlagService.getAllFeatures());
String response = templateService.renderTemplate("disable_features_response", model);

View File

@@ -34,7 +34,7 @@ public class Enable extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
if(commandContext.getParameters().getParameters().size() == 0) {
if(commandContext.getParameters().getParameters().isEmpty()) {
EnableModel model = (EnableModel) ContextConverter.fromCommandContext(commandContext, EnableModel.class);
model.setFeatures(featureFlagService.getAllFeatures());
String response = templateService.renderTemplate("enable_features_response", model);

View File

@@ -43,9 +43,9 @@ public class MakeAffected extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.makeRoleAffectedByCommand(command, role);
});
feature.getCommands().forEach(command ->
commandService.makeRoleAffectedByCommand(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.makeRoleAffectedByCommand(command, role);

View File

@@ -43,9 +43,9 @@ public class MakeImmune extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.makeRoleImmuneForCommand(command, role);
});
feature.getCommands().forEach(command ->
commandService.makeRoleImmuneForCommand(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.makeRoleImmuneForCommand(command, role);

View File

@@ -40,9 +40,9 @@ public class Restrict extends AbstractConditionableCommand {
String name = (String) commandContext.getParameters().getParameters().get(0);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer());
});
feature.getCommands().forEach(command ->
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer())
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer());

View File

@@ -42,9 +42,9 @@ public class Help implements Command {
if(module != null){
sb.append("Help | Module overview \n");
sb.append(getModule(module, 0, false));
module.getCommands().forEach(command -> {
sb.append(getCommand(command));
});
module.getCommands().forEach(command ->
sb.append(getCommand(command))
);
} else {
Command command = commandStructure.getCommandWithName(parameterValue);
if(command != null) {
@@ -109,9 +109,9 @@ public class Help implements Command {
sb.append(String.format(intentation +"**%s** \n", info.getName()));
sb.append(String.format(intentation + "%s \n", info.getDescription()));
if(recursive) {
module.getSubModules().forEach(subModule -> {
sb.append(getModule(subModule, depth + 1, true));
});
module.getSubModules().forEach(subModule ->
sb.append(getModule(subModule, depth + 1, true))
);
}
sb.append("\n");
return sb.toString();

View File

@@ -27,9 +27,9 @@ public class Echo extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
StringBuilder sb = new StringBuilder();
commandContext.getParameters().getParameters().forEach(o -> {
sb.append(o.toString());
});
commandContext.getParameters().getParameters().forEach(o ->
sb.append(o.toString())
);
EchoModel model = EchoModel.builder().text(sb.toString()).build();
commandContext.getChannel().sendMessage(templateService.renderTemplate(TEMPLATE_NAME, model)).queue();
return CommandResult.fromSuccess();

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.core.commands.utility;
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.execution.CommandContext;

View File

@@ -1,21 +0,0 @@
package dev.sheldan.abstracto.core.commands.utility;
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
import org.springframework.stereotype.Component;
@Component
public class UtilityModuleInterface implements ModuleInterface {
public static final String UTILITY = "utility";
@Override
public ModuleInfo getInfo() {
return ModuleInfo.builder().name(UTILITY).description("General utilities").build();
}
@Override
public String getParentModule() {
return "default";
}
}

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;

View File

@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.Consumer;
@Component
@Slf4j
@@ -32,9 +33,8 @@ public class MessageDeletedListenerBean extends ListenerAdapter {
@Override
@Transactional
public void onGuildMessageDelete(@Nonnull GuildMessageDeleteEvent event) {
messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong()).thenAccept(cachedMessage -> {
self.executeListener(cachedMessage);
});
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage -> self.executeListener(cachedMessage);
messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong()).thenAccept(cachedMessageConsumer);
}
@Transactional

View File

@@ -67,9 +67,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
}
private void addReactionIfNotThere(CachedMessage message, CachedReaction reaction, AUser userReacting) {
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 -> {
return EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote());
}).findAny();
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 ->
EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote())
).findAny();
if(!existingReaction.isPresent()) {
message.getReactions().add(reaction);
} else {
@@ -82,9 +82,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
}
private void removeReactionIfThere(CachedMessage message, CachedReaction reaction, AUser userReacting) {
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 -> {
return EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote());
}).findAny();
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 ->
EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote())
).findAny();
if(existingReaction.isPresent()) {
CachedReaction cachedReaction = existingReaction.get();
cachedReaction.getUsers().removeIf(user -> user.getId().equals(userReacting.getId()));
@@ -118,9 +118,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
asyncMessageFromCache.thenAccept(cachedMessage -> {
CompletableFuture<CachedReaction> future = new CompletableFuture<>();
messageCache.getCachedReactionFromReaction(future, event.getReaction());
future.thenAccept(reaction -> {
self.callRemoveListeners(event, cachedMessage, reaction);
});
future.thenAccept(reaction ->
self.callRemoveListeners(event, cachedMessage, reaction)
);
messageCache.putMessageInCache(cachedMessage);
});

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
public class BotServiceBean implements BotService {
public static final String GUILD_NOT_FOUND = "Guild %s not found.";
private JDA instance;
@Override
@@ -58,7 +59,7 @@ public class BotServiceBean implements BotService {
}
}
else {
throw new GuildException(String.format("Guild %s not found.", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
}
@@ -68,7 +69,7 @@ public class BotServiceBean implements BotService {
if(guildById != null) {
return guildById.getMemberById(memberId);
} else {
throw new RuntimeException(String.format("Guild %s not found.", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
}
@@ -78,7 +79,7 @@ public class BotServiceBean implements BotService {
if(guildById != null) {
return isUserInGuild(guildById, aUserInAServer);
} else {
throw new RuntimeException(String.format("Guild %s not found.", aUserInAServer.getServerReference().getId()));
throw new GuildException(String.format(GUILD_NOT_FOUND, aUserInAServer.getServerReference().getId()));
}
}
@@ -120,7 +121,7 @@ public class BotServiceBean implements BotService {
Emote emoteById = guild.getEmoteById(emote.getEmoteId());
return Optional.ofNullable(emoteById);
}
throw new GuildException(String.format("Not able to find server %s", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
@Override
@@ -135,7 +136,7 @@ public class BotServiceBean implements BotService {
Guild guild = guildOptional.get();
return Optional.ofNullable(guild.getTextChannelById(textChannelId));
}
throw new GuildException(String.format("Not able to find guild %s", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
@Override
@@ -143,6 +144,11 @@ public class BotServiceBean implements BotService {
return Optional.ofNullable(instance.getGuildById(serverId));
}
@Override
public Guild getGuildByIdNullable(Long serverId) {
return instance.getGuildById(serverId);
}
@Override
public void shutdown() {

View File

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
@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;
@@ -61,7 +64,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(channel.getServer().getId());
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found.", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
channelGroupManagementService.addChannelToChannelGroup(channelGroup, channel);
}
@@ -82,7 +85,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(channel.getServer().getId());
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
channelGroupManagementService.removeChannelFromChannelGroup(channelGroup, channel);
}
@@ -92,11 +95,11 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandException(String.format("Command %s not found.", commandName));
throw new CommandException(String.format(COMMAND_NOT_FOUND, commandName));
}
channelGroupCommandManagementService.setCommandInGroupTo(command, channelGroup, false);
}
@@ -106,11 +109,11 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandException(String.format("Command %s not found.", commandName));
throw new CommandException(String.format(COMMAND_NOT_FOUND, commandName));
}
channelGroupCommandManagementService.setCommandInGroupTo(command, channelGroup, true);
}

View File

@@ -95,17 +95,17 @@ public class ChannelServiceBean implements ChannelService {
String messageText = messageToSend.getMessage();
List<CompletableFuture<Message>> futures = new ArrayList<>();
if(StringUtils.isBlank(messageText)) {
messageToSend.getEmbeds().forEach(embed -> {
futures.add(sendEmbedInAChannelFuture(embed, textChannel));
});
messageToSend.getEmbeds().forEach(embed ->
futures.add(sendEmbedInAChannelFuture(embed, textChannel))
);
} else {
MessageAction messageAction = textChannel.sendMessage(messageText);
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
CompletableFuture<Message> messageFuture = messageAction.embed(messageToSend.getEmbeds().get(0)).submit();
futures.add(messageFuture);
messageToSend.getEmbeds().stream().skip(1).forEach(embed -> {
futures.add(sendEmbedInAChannelFuture(embed, textChannel));
});
messageToSend.getEmbeds().stream().skip(1).forEach(embed ->
futures.add(sendEmbedInAChannelFuture(embed, textChannel))
);
} else {
futures.add(messageAction.submit());
}
@@ -134,11 +134,11 @@ public class ChannelServiceBean implements ChannelService {
MessageAction messageAction;
if(!StringUtils.isBlank(messageToSend.getMessage())) {
messageAction = channel.editMessageById(messageId, messageToSend.getMessage());
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
messageAction = messageAction.embed(messageToSend.getEmbeds().get(0));
}
} else {
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
messageAction = channel.editMessageById(messageId, messageToSend.getEmbeds().get(0));
} else {
throw new AbstractoRunTimeException("Message to send did not contain anything to send.");

View File

@@ -80,9 +80,9 @@ public class MessageCacheBean implements MessageCache {
Optional<TextChannel> textChannelByIdOptional = botService.getTextChannelFromServer(guildOptional.get(), textChannelId);
if(textChannelByIdOptional.isPresent()) {
TextChannel textChannel = textChannelByIdOptional.get();
textChannel.retrieveMessageById(messageId).queue(message -> {
buildCachedMessageFromMessage(future, message);
});
textChannel.retrieveMessageById(messageId).queue(message ->
buildCachedMessageFromMessage(future, message)
);
} else {
log.error("Not able to load message {} in channel {} in guild {}. Text channel not found.", messageId, textChannelId, guildId);
future.completeExceptionally(new ChannelException(String.format("Not able to load message %s. Text channel %s not found in guild %s", messageId, textChannelId, guildId)));
@@ -98,13 +98,13 @@ public class MessageCacheBean implements MessageCache {
@Async
public void buildCachedMessageFromMessage(CompletableFuture<CachedMessage> future, Message message) {
List<String> attachmentUrls = new ArrayList<>();
message.getAttachments().forEach(attachment -> {
attachmentUrls.add(attachment.getProxyUrl());
});
message.getAttachments().forEach(attachment ->
attachmentUrls.add(attachment.getProxyUrl())
);
List<CachedEmbed> embeds = new ArrayList<>();
message.getEmbeds().forEach(embed -> {
embeds.add(getCachedEmbedFromEmbed(embed));
});
message.getEmbeds().forEach(embed ->
embeds.add(getCachedEmbedFromEmbed(embed))
);
List<CompletableFuture<CachedReaction>> futures = new ArrayList<>();
message.getReactions().forEach(messageReaction -> {
@@ -113,7 +113,7 @@ public class MessageCacheBean implements MessageCache {
futures.add(future1);
});
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
future.complete(CachedMessage.builder()
.authorId(message.getAuthor().getIdLong())
.serverId(message.getGuild().getIdLong())
@@ -124,8 +124,8 @@ public class MessageCacheBean implements MessageCache {
.reactions(getFutures(futures))
.timeCreated(Instant.from(message.getTimeCreated()))
.attachmentUrls(attachmentUrls)
.build());
});
.build())
);
}
private List<CachedReaction> getFutures(List<CompletableFuture<CachedReaction>> futures) {

View File

@@ -88,9 +88,9 @@ public class MessageServiceBean implements MessageService {
public void sendMessageToUser(User user, String text, TextChannel feedbackChannel) {
CompletableFuture<Message> messageFuture = new CompletableFuture<>();
user.openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage(text).queue(messageFuture::complete, messageFuture::completeExceptionally);
});
user.openPrivateChannel().queue(privateChannel ->
privateChannel.sendMessage(text).queue(messageFuture::complete, messageFuture::completeExceptionally)
);
messageFuture.exceptionally(e -> {
log.warn("Failed to send message. ", e);

View File

@@ -119,10 +119,10 @@ public class PostTargetServiceBean implements PostTargetService {
existingMessage -> existingMessage
.editMessage(messageToSend.getEmbeds().get(0))
.submit().thenAccept(message -> future.get(0).complete(message)),
throwable -> {
throwable ->
sendEmbedInPostTarget(messageToSend, target).get(0)
.thenAccept(message -> future.get(0).complete(message));
});
.thenAccept(message -> future.get(0).complete(message))
);
} else {
textChannelForPostTarget
.retrieveMessageById(messageId)
@@ -131,10 +131,10 @@ public class PostTargetServiceBean implements PostTargetService {
.editMessage(messageToSend.getMessage())
.embed(messageToSend.getEmbeds().get(0))
.submit().thenAccept(message -> future.get(0).complete(message)),
throwable -> {
throwable ->
sendEmbedInPostTarget(messageToSend, target).get(0)
.thenAccept(message -> future.get(0).complete(message));
});
.thenAccept(message -> future.get(0).complete(message))
);
}
}
@@ -145,7 +145,7 @@ public class PostTargetServiceBean implements PostTargetService {
}
@Override
public void throwIfPostTargetIsNotDefined(String name, Long serverId) throws ChannelException {
public void throwIfPostTargetIsNotDefined(String name, Long serverId) {
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
if(postTarget == null) {
throw new ChannelException(String.format("Post target %s is not defined.", name));

View File

@@ -73,9 +73,9 @@ public class StartupServiceBean implements Startup {
if(newGuild != null){
synchronizeRolesOf(newGuild, newAServer);
synchronizeChannelsOf(newGuild, newAServer);
configListeners.forEach(serverConfigListener -> {
serverConfigListener.updateServerConfig(newAServer);
});
configListeners.forEach(serverConfigListener ->
serverConfigListener.updateServerConfig(newAServer)
);
}
});
@@ -108,8 +108,8 @@ public class StartupServiceBean implements Startup {
});
Set<Long> noLongAvailable = SetUtils.difference(knownChannelsIds, existingChannelsIds);
noLongAvailable.forEach(aLong -> {
channelManagementService.markAsDeleted(aLong);
});
noLongAvailable.forEach(aLong ->
channelManagementService.markAsDeleted(aLong)
);
}
}

View File

@@ -8,6 +8,10 @@ import java.util.Set;
import java.util.stream.Collectors;
public class SnowflakeUtils {
private SnowflakeUtils() {
}
public static Set<Long> getOwnItemsIds(List<? extends SnowFlake> elements){
return elements.stream().map(SnowFlake::getId).collect(Collectors.toSet());
}