mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-26 13:46:19 +00:00
[AB-136] replacing some rare occurrences where fake objects where used for actual database operations
replacing a few sync commands with async commands refactoring parameters in assignable role place service bean fixing emote parameter handler to also consider default emojis removing unused description in command replacing some ARole parameters with Role parameters, so we can be sure they exists added a few TODOs marking exception changes required
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class DeleteAssignableRolePlace extends AbstractConditionableCommand {
|
||||
@@ -22,12 +23,12 @@ public class DeleteAssignableRolePlace extends AbstractConditionableCommand {
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
service.deleteAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name);
|
||||
return CommandResult.fromSuccess();
|
||||
return service.deleteAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +41,7 @@ public class DeleteAssignableRolePlace extends AbstractConditionableCommand {
|
||||
.module(AssignableRoleModule.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -34,7 +34,8 @@ public class EditAssignableRolePlaceText extends AbstractConditionableCommand {
|
||||
String name = (String) parameters.get(0);
|
||||
String newText = (String) parameters.get(1);
|
||||
|
||||
return service.changeText(commandContext.getUserInitiatedContext().getServer(), name, newText).thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
return service.changeText(commandContext.getUserInitiatedContext().getServer(), name, newText)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class RemoveRoleFromAssignableRolePlace extends AbstractConditionableCommand {
|
||||
@@ -23,13 +24,13 @@ public class RemoveRoleFromAssignableRolePlace extends AbstractConditionableComm
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote emote = (FullEmote) parameters.get(1);
|
||||
service.removeRoleFromAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, emote);
|
||||
return CommandResult.fromSuccess();
|
||||
return service.removeRoleFromAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, emote)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +44,7 @@ public class RemoveRoleFromAssignableRolePlace extends AbstractConditionableComm
|
||||
.module(AssignableRoleModule.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class SetAssignableRolePosition extends AbstractConditionableCommand {
|
||||
@@ -23,14 +24,14 @@ public class SetAssignableRolePosition extends AbstractConditionableCommand {
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote emote = (FullEmote) parameters.get(1);
|
||||
Integer newPosition = (Integer) parameters.get(2);
|
||||
service.setEmoteToPosition(commandContext.getUserInitiatedContext().getServer(), name, emote, newPosition);
|
||||
return CommandResult.fromSuccess();
|
||||
return service.setEmoteToPosition(commandContext.getUserInitiatedContext().getServer(), name, emote, newPosition)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +46,7 @@ public class SetAssignableRolePosition extends AbstractConditionableCommand {
|
||||
.module(AssignableRoleModule.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -27,6 +27,7 @@ public class ShowAssignableRolePlaceConfig extends AbstractConditionableCommand
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
// TODO refactor to return something to be posted in this command here instead of relying it to be posted somewhere else
|
||||
service.showAssignablePlaceConfig(commandContext.getUserInitiatedContext().getServer(), name, commandContext.getChannel());
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class TestAssignableRolePlace extends AbstractConditionableCommand {
|
||||
@@ -22,12 +23,12 @@ public class TestAssignableRolePlace extends AbstractConditionableCommand {
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
service.testAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, commandContext.getChannel());
|
||||
return CommandResult.fromSuccess();
|
||||
return service.testAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, commandContext.getChannel())
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +41,7 @@ public class TestAssignableRolePlace extends AbstractConditionableCommand {
|
||||
.module(AssignableRoleModule.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -14,7 +14,6 @@ import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePl
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandParameterKeyValueWrongTypeException;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.exception.EmoteNotUsableException;
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
@@ -35,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@@ -169,16 +167,16 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
if(channelOptional.isPresent()) {
|
||||
TextChannel textChannel = channelOptional.get();
|
||||
if(latestPost.getAssignableRoles().size() < 20) {
|
||||
return addReactionToExistingAssignableRolePlacePost(fakeEmote, description, assignableRolePlace, placeId, roleId, serverId, latestPost, messageToSend, textChannel, fakeEmote);
|
||||
return addReactionToExistingAssignableRolePlacePost(fakeEmote, description, assignableRolePlace, placeId, roleId, serverId, latestPost, messageToSend, textChannel);
|
||||
} else {
|
||||
return addNewMessageToAssignableRolePlace(placeName, fakeEmote, description, roleId, serverId, messageToSend, textChannel, fakeEmote);
|
||||
return addNewMessageToAssignableRolePlace(placeName, fakeEmote, description, roleId, serverId, messageToSend, textChannel);
|
||||
}
|
||||
} else {
|
||||
throw new ChannelNotFoundException(latestPost.getUsedChannel().getId());
|
||||
}
|
||||
} else {
|
||||
log.info("Added emote to assignable place {} in server {}, but no message post yet.", placeName, serverId);
|
||||
self.addAssignableRoleInstanceWithoutPost(placeId, roleId, fakeEmote, description);
|
||||
self.addAssignableRoleInstanceWithoutPost(placeId, roleId, fakeEmote, description, serverId);
|
||||
}
|
||||
} else {
|
||||
throw new EmoteNotUsableException(fakeEmote.getEmote());
|
||||
@@ -186,7 +184,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> addReactionToExistingAssignableRolePlacePost(FullEmote fakeEmote, String description, AssignableRolePlace assignableRolePlace, Long placeId, Long roleId, Long serverId, AssignableRolePlacePost latestPost, MessageToSend messageToSend, TextChannel textChannel, FullEmote emote) {
|
||||
private CompletableFuture<Void> addReactionToExistingAssignableRolePlacePost(FullEmote fakeEmote, String description, AssignableRolePlace assignableRolePlace, Long placeId, Long roleId, Long serverId, AssignableRolePlacePost latestPost, MessageToSend messageToSend, TextChannel textChannel) {
|
||||
// TODO maybe refactor to use the same message object, so we dont need to retrieve it twice and do in parallel
|
||||
return textChannel.retrieveMessageById(latestPost.getId()).submit()
|
||||
.thenCompose(message -> messageService.addReactionToMessageWithFuture(fakeEmote.getFakeEmote(), serverId, message))
|
||||
@@ -195,16 +193,16 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
return channelService.editEmbedMessageInAChannel(embedToUse, textChannel, latestPost.getId());
|
||||
})
|
||||
.thenCompose(message -> {
|
||||
self.addAssignableRoleInstanceWithPost(message.getIdLong(), placeId, roleId, description, emote);
|
||||
self.addAssignableRoleInstanceWithPost(message.getIdLong(), placeId, roleId, description, fakeEmote, serverId);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> addNewMessageToAssignableRolePlace(String placeName, FullEmote fakeEmote, String description, Long roleId, Long serverId, MessageToSend messageToSend, TextChannel textChannel, FullEmote emote) {
|
||||
private CompletableFuture<Void> addNewMessageToAssignableRolePlace(String placeName, FullEmote fakeEmote, String description, Long roleId, Long serverId, MessageToSend messageToSend, TextChannel textChannel) {
|
||||
MessageEmbed embedToUse = messageToSend.getEmbeds().get(messageToSend.getEmbeds().size() - 1);
|
||||
return channelService.sendEmbedToChannel(embedToUse, textChannel)
|
||||
.thenCompose(message -> messageService.addReactionToMessageWithFuture(fakeEmote.getFakeEmote(), serverId, message).thenAccept(aVoid ->
|
||||
self.addNewlyCreatedAssignablePlacePost(placeName, description, roleId, serverId, textChannel, message, emote)
|
||||
self.addNewlyCreatedAssignablePlacePost(placeName, description, roleId, serverId, textChannel, message, fakeEmote)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -229,15 +227,15 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addAssignableRoleInstanceWithPost(Long messageId, Long placeId, Long roleId, String description, FullEmote fakeEmote) {
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), fakeEmote.getEmote().getGuild().getIdLong(), false);
|
||||
public void addAssignableRoleInstanceWithPost(Long messageId, Long placeId, Long roleId, String description, FullEmote fakeEmote, Long serverId) {
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), serverId, false);
|
||||
emote.setChangeable(false);
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(placeId, emote.getId(), roleId, description, messageId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addAssignableRoleInstanceWithoutPost(Long placeId, Long roleId, FullEmote fakeEmote, String description) {
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), fakeEmote.getEmote().getGuild().getIdLong(), false);
|
||||
public void addAssignableRoleInstanceWithoutPost(Long placeId, Long roleId, FullEmote fakeEmote, String description, Long serverId) {
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), serverId, false);
|
||||
emote.setChangeable(false);
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(placeId, emote.getId(), roleId, description);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user