[AB-150] creating repost detection feature including configuration and documentation

adding http and hash service
adding ability to add default emotes to a message to message service
adding message embedded listener to wrap the embedded event
adding custom channel groups which can be defined by modules, in case a change on a channel group (only created and updated) happens a listener is available in order to sync the state in dependant areas
changing command receiver re-throwing abstracto runtime exceptions in order to display them better
changing channel group parameter handler to throw an exception in case the channel group was not found
adding User in a server parameter handler
split channel not found exception to be able to differentiate between not found in database and not found in guild
changing exception handling in command received handler to handle the case for only one parameter handler future which failed (the whole single future failed, which was not reported)
changing parameter type of `removeFromChannelGroup` to AChannel in order to be able to delete channels in the database via ID
moving method to mock utils for mocking consumer
removing parameter validation from commands, as it should be done in the command received handler and parameter handlers anyway
This commit is contained in:
Sheldan
2020-12-04 00:38:18 +01:00
parent e966c710ce
commit 325264a325
249 changed files with 5310 additions and 686 deletions

View File

@@ -23,7 +23,6 @@ public class ActivateAssignableRolePlace extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
service.activateAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name); service.activateAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name);

View File

@@ -32,7 +32,6 @@ public class AddRoleToAssignableRolePost extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
FullEmote emote = (FullEmote) parameters.get(1); FullEmote emote = (FullEmote) parameters.get(1);

View File

@@ -33,7 +33,6 @@ public class CreateAssignableRolePost extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
MessageChannel channel = (TextChannel) parameters.get(1); MessageChannel channel = (TextChannel) parameters.get(1);

View File

@@ -23,7 +23,6 @@ public class DeactivateAssignableRolePlace extends AbstractConditionableCommand
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
service.deactivateAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name); service.deactivateAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name);

View File

@@ -24,7 +24,6 @@ public class DeleteAssignableRolePlace extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
return service.deleteAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name) return service.deleteAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name)

View File

@@ -29,7 +29,6 @@ public class EditAssignableRolePlaceText extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
String newText = (String) parameters.get(1); String newText = (String) parameters.get(1);

View File

@@ -24,7 +24,6 @@ public class MoveAssignableRolePlace extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
TextChannel newChannel = (TextChannel) parameters.get(1); TextChannel newChannel = (TextChannel) parameters.get(1);

View File

@@ -25,7 +25,6 @@ public class RemoveRoleFromAssignableRolePlace extends AbstractConditionableComm
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
FullEmote emote = (FullEmote) parameters.get(1); FullEmote emote = (FullEmote) parameters.get(1);

View File

@@ -24,7 +24,6 @@ public class SetAssignableRolePosition extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
FullEmote emote = (FullEmote) parameters.get(1); FullEmote emote = (FullEmote) parameters.get(1);

View File

@@ -30,7 +30,6 @@ public class SetupAssignableRolePlace extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
return service.setupAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name) return service.setupAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name)

View File

@@ -24,7 +24,6 @@ public class ShowAssignableRolePlaceConfig extends AbstractConditionableCommand
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); 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 // TODO refactor to return something to be posted in this command here instead of relying it to be posted somewhere else

View File

@@ -30,7 +30,6 @@ public class SwapAssignableRolePosition extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
FullEmote firstEmote = (FullEmote) parameters.get(1); FullEmote firstEmote = (FullEmote) parameters.get(1);

View File

@@ -24,7 +24,6 @@ public class TestAssignableRolePlace extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String name = (String) parameters.get(0); String name = (String) parameters.get(0);
return service.testAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, commandContext.getChannel()) return service.testAssignableRolePlace(commandContext.getUserInitiatedContext().getServer(), name, commandContext.getChannel())

View File

@@ -14,7 +14,7 @@ import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePl
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService; import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService;
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException; import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
import dev.sheldan.abstracto.core.command.exception.CommandParameterKeyValueWrongTypeException; import dev.sheldan.abstracto.core.command.exception.CommandParameterKeyValueWrongTypeException;
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException; import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
import dev.sheldan.abstracto.core.exception.EmoteNotUsableException; import dev.sheldan.abstracto.core.exception.EmoteNotUsableException;
import dev.sheldan.abstracto.core.models.FullEmote; import dev.sheldan.abstracto.core.models.FullEmote;
import dev.sheldan.abstracto.core.models.database.*; import dev.sheldan.abstracto.core.models.database.*;
@@ -185,7 +185,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
return addNewMessageToAssignableRolePlace(placeId, fakeEmote, description, roleId, serverId, messageToSend, textChannel); return addNewMessageToAssignableRolePlace(placeId, fakeEmote, description, roleId, serverId, messageToSend, textChannel);
} }
} else { } else {
throw new ChannelNotFoundException(latestPost.getUsedChannel().getId()); throw new ChannelNotInGuildException(latestPost.getUsedChannel().getId());
} }
} else { } else {
log.trace("Added emote to assignable place {} in server {}, but no message post yet.", placeId, serverId); log.trace("Added emote to assignable place {} in server {}, but no message post yet.", placeId, serverId);
@@ -374,7 +374,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
log.info("Refreshing text for assignable role place {} in channel {} in post {}.", place.getId(), channelId, firstPost.getId()); log.info("Refreshing text for assignable role place {} in channel {} in post {}.", place.getId(), channelId, firstPost.getId());
return channelService.editEmbedMessageInAChannel(renderedMessage.getEmbeds().get(0), channelOptional.get(), firstPost.getId()).thenCompose(message -> CompletableFuture.completedFuture(null)); return channelService.editEmbedMessageInAChannel(renderedMessage.getEmbeds().get(0), channelOptional.get(), firstPost.getId()).thenCompose(message -> CompletableFuture.completedFuture(null));
} }
throw new ChannelNotFoundException(channelId); throw new ChannelNotInGuildException(channelId);
} }
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }

View File

@@ -31,7 +31,6 @@ public class DisableExpForRole extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
ARole role = (ARole) parameters.get(0); ARole role = (ARole) parameters.get(0);
ARole actualRole = roleManagementService.findRole(role.getId()); ARole actualRole = roleManagementService.findRole(role.getId());

View File

@@ -32,7 +32,6 @@ public class DisableExpGain extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Member para = (Member) commandContext.getParameters().getParameters().get(0); Member para = (Member) commandContext.getParameters().getParameters().get(0);
AUserInAServer userInAServer = userInServerManagementService.loadUser(para); AUserInAServer userInAServer = userInServerManagementService.loadUser(para);
aUserExperienceService.disableExperienceForUser(userInAServer); aUserExperienceService.disableExperienceForUser(userInAServer);

View File

@@ -31,7 +31,6 @@ public class EnableExpForRole extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
ARole role = (ARole) commandContext.getParameters().getParameters().get(0); ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
ARole actualRole = roleManagementService.findRole(role.getId()); ARole actualRole = roleManagementService.findRole(role.getId());
if(disabledExpRoleManagementService.isExperienceDisabledForRole(actualRole)) { if(disabledExpRoleManagementService.isExperienceDisabledForRole(actualRole)) {

View File

@@ -32,7 +32,6 @@ public class EnableExpGain extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Member para = (Member) commandContext.getParameters().getParameters().get(0); Member para = (Member) commandContext.getParameters().getParameters().get(0);
AUserInAServer userInAServer = userInServerManagementService.loadUser(para); AUserInAServer userInAServer = userInServerManagementService.loadUser(para);
aUserExperienceService.enableExperienceForUser(userInAServer); aUserExperienceService.enableExperienceForUser(userInAServer);

View File

@@ -30,7 +30,6 @@ public class ExpScale extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Double scale = (Double) commandContext.getParameters().getParameters().get(0); Double scale = (Double) commandContext.getParameters().getParameters().get(0);
Long guildId = commandContext.getGuild().getIdLong(); Long guildId = commandContext.getGuild().getIdLong();
configService.setDoubleValue(EXP_MULTIPLIER_KEY, guildId, scale); configService.setDoubleValue(EXP_MULTIPLIER_KEY, guildId, scale);

View File

@@ -54,7 +54,6 @@ public class LeaderBoardCommand extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
// parameter is optional, in case its not present, we default to the 0th page // parameter is optional, in case its not present, we default to the 0th page
Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 1; Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 1;

View File

@@ -42,7 +42,6 @@ public class ListDisabledExperienceRoles extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<ADisabledExpRole> disabledRolesForServer = disabledExpRoleManagementService.getDisabledRolesForServer(commandContext.getUserInitiatedContext().getServer()); List<ADisabledExpRole> disabledRolesForServer = disabledExpRoleManagementService.getDisabledRolesForServer(commandContext.getUserInitiatedContext().getServer());
DisabledExperienceRolesModel disabledExperienceRolesModel = (DisabledExperienceRolesModel) ContextConverter.fromCommandContext(commandContext, DisabledExperienceRolesModel.class); DisabledExperienceRolesModel disabledExperienceRolesModel = (DisabledExperienceRolesModel) ContextConverter.fromCommandContext(commandContext, DisabledExperienceRolesModel.class);
disabledRolesForServer.forEach(aDisabledExpRole -> { disabledRolesForServer.forEach(aDisabledExpRole -> {

View File

@@ -66,7 +66,6 @@ public class Rank extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
RankModel rankModel = (RankModel) ContextConverter.slimFromCommandContext(commandContext, RankModel.class); RankModel rankModel = (RankModel) ContextConverter.slimFromCommandContext(commandContext, RankModel.class);
LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(commandContext.getUserInitiatedContext().getAUserInAServer()); LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(commandContext.getUserInitiatedContext().getAUserInAServer());
CompletableFuture<LeaderBoardEntryModel> future = converter.fromLeaderBoardEntry(userRank); CompletableFuture<LeaderBoardEntryModel> future = converter.fromLeaderBoardEntry(userRank);

View File

@@ -41,7 +41,6 @@ public class SetExpRole extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
Integer level = (Integer) commandContext.getParameters().getParameters().get(0); Integer level = (Integer) commandContext.getParameters().getParameters().get(0);
Role role = (Role) commandContext.getParameters().getParameters().get(1); Role role = (Role) commandContext.getParameters().getParameters().get(1);
log.info("Setting role {} to be used for level {} on server {}", role.getId(), level, role.getGuild().getId()); log.info("Setting role {} to be used for level {} on server {}", role.getId(), level, role.getGuild().getId());

View File

@@ -33,7 +33,6 @@ public class UnSetExpRole extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
ARole role = (ARole) commandContext.getParameters().getParameters().get(0); ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
ARole actualRole = roleManagementService.findRole(role.getId()); ARole actualRole = roleManagementService.findRole(role.getId());
// do not check for the existence of the role, because if the role was deleted, users should be able // do not check for the existence of the role, because if the role was deleted, users should be able

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole; import dev.sheldan.abstracto.core.models.database.ARole;
@@ -34,16 +32,6 @@ public class DisableExpForRoleTest {
@Mock @Mock
private DisabledExpRoleManagementService disabledExpRoleManagementService; private DisabledExpRoleManagementService disabledExpRoleManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testExecuteCommandForNotDisabledRole() { public void testExecuteCommandForNotDisabledRole() {
executeDisableExpForRoleTest(false, 1); executeDisableExpForRoleTest(false, 1);

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer; import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -34,16 +32,6 @@ public class DisableExpGainTest {
@Mock @Mock
private UserInServerManagementService userInServerManagementService; private UserInServerManagementService userInServerManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testDisableExpForMember() { public void testDisableExpForMember() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole; import dev.sheldan.abstracto.core.models.database.ARole;
@@ -32,16 +30,6 @@ public class EnableExpForRoleTest {
@Mock @Mock
private RoleManagementService roleManagementService; private RoleManagementService roleManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testExecuteCommandForNotDisabledRole() { public void testExecuteCommandForNotDisabledRole() {
executeEnableExpForRoleTest(false, 0); executeEnableExpForRoleTest(false, 0);

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer; import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -34,16 +32,6 @@ public class EnableExpGainTest {
@Mock @Mock
private UserInServerManagementService userInServerManagementService; private UserInServerManagementService userInServerManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testEnableExpForMember() { public void testEnableExpForMember() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.ConfigService; import dev.sheldan.abstracto.core.service.ConfigService;
@@ -26,16 +24,6 @@ public class ExpScaleTest {
@Mock @Mock
private ConfigService configService; private ConfigService configService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testSetExpScaleForGuild() { public void testSetExpScaleForGuild() {
double newScale = 4.5; double newScale = 4.5;

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
@@ -44,11 +43,6 @@ public class LeaderBoardCommandTest {
@Mock @Mock
private LeaderBoardModelConverter converter; private LeaderBoardModelConverter converter;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testLeaderBoardWithNoParameter() { public void testLeaderBoardWithNoParameter() {
testLeaderBoardCommand(CommandTestUtilities.getNoParameters(), 1); testLeaderBoardCommand(CommandTestUtilities.getNoParameters(), 1);

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.RoleService; import dev.sheldan.abstracto.core.service.RoleService;
@@ -37,28 +35,6 @@ public class SetExpRoleTest {
@Mock @Mock
private RoleManagementService roleManagementService; private RoleManagementService roleManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = InsufficientParametersException.class)
public void testRoleMissing() {
CommandContext context = CommandTestUtilities.getWithParameters(Arrays.asList(4));
testUnit.executeAsync(context);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testLevelProvidedButNotRole() {
CommandContext context = CommandTestUtilities.getWithParameters(Arrays.asList(4, ""));
testUnit.executeAsync(context);
}
@Test @Test
public void setExpRole() { public void setExpRole() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.experience.commands; package dev.sheldan.abstracto.experience.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole; import dev.sheldan.abstracto.core.models.database.ARole;
@@ -34,16 +32,6 @@ public class UnSetExpRoleTest {
@Mock @Mock
private RoleManagementService roleManagementService; private RoleManagementService roleManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void setUnSetExpRole() { public void setUnSetExpRole() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();

View File

@@ -34,7 +34,6 @@ public class Ban extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
String defaultReason = templateService.renderSimpleTemplate(BAN_DEFAULT_REASON_TEMPLATE); String defaultReason = templateService.renderSimpleTemplate(BAN_DEFAULT_REASON_TEMPLATE);

View File

@@ -29,7 +29,6 @@ public class BanId extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Long userId = (Long) parameters.get(0); Long userId = (Long) parameters.get(0);
String defaultReason = templateService.renderSimpleTemplate(Ban.BAN_DEFAULT_REASON_TEMPLATE); String defaultReason = templateService.renderSimpleTemplate(Ban.BAN_DEFAULT_REASON_TEMPLATE);

View File

@@ -25,7 +25,6 @@ public class DecayAllWarnings extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
return warnService.decayAllWarningsForServer(commandContext.getUserInitiatedContext().getServer()) return warnService.decayAllWarningsForServer(commandContext.getUserInitiatedContext().getServer())
.thenApply(aVoid -> CommandResult.fromSuccess()); .thenApply(aVoid -> CommandResult.fromSuccess());
} }

View File

@@ -34,7 +34,6 @@ public class DeleteNote extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Long id = (Long) commandContext.getParameters().getParameters().get(0); Long id = (Long) commandContext.getParameters().getParameters().get(0);
if(userNoteManagementService.noteExists(id, commandContext.getUserInitiatedContext().getServer())) { if(userNoteManagementService.noteExists(id, commandContext.getUserInitiatedContext().getServer())) {
userNoteManagementService.deleteNote(id, commandContext.getUserInitiatedContext().getServer()); userNoteManagementService.deleteNote(id, commandContext.getUserInitiatedContext().getServer());

View File

@@ -29,7 +29,6 @@ public class DeleteWarning extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Long warnId = (Long) commandContext.getParameters().getParameters().get(0); Long warnId = (Long) commandContext.getParameters().getParameters().get(0);
Optional<Warning> optional = warnManagementService.findByIdOptional(warnId, commandContext.getGuild().getIdLong()); Optional<Warning> optional = warnManagementService.findByIdOptional(warnId, commandContext.getGuild().getIdLong());
optional.ifPresent(warning -> warnManagementService.deleteWarning(warning)); optional.ifPresent(warning -> warnManagementService.deleteWarning(warning));

View File

@@ -32,7 +32,6 @@ public class Kick extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
String defaultReason = templateService.renderSimpleTemplate(KICK_DEFAULT_REASON_TEMPLATE); String defaultReason = templateService.renderSimpleTemplate(KICK_DEFAULT_REASON_TEMPLATE);

View File

@@ -37,7 +37,6 @@ public class Purge extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
Integer amountOfMessages = (Integer) commandContext.getParameters().getParameters().get(0); Integer amountOfMessages = (Integer) commandContext.getParameters().getParameters().get(0);
Member memberToPurgeMessagesOf = null; Member memberToPurgeMessagesOf = null;
if(commandContext.getParameters().getParameters().size() == 2) { if(commandContext.getParameters().getParameters().size() == 2) {

View File

@@ -28,7 +28,6 @@ public class SlowMode extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
TextChannel channel; TextChannel channel;
String durationString = (String) commandContext.getParameters().getParameters().get(0); String durationString = (String) commandContext.getParameters().getParameters().get(0);
Duration duration; Duration duration;

View File

@@ -30,7 +30,6 @@ public class UserNoteCommand extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
String text = (String) parameters.get(1); String text = (String) parameters.get(1);

View File

@@ -49,7 +49,6 @@ public class UserNotes extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
List<UserNote> userNotes; List<UserNote> userNotes;

View File

@@ -34,7 +34,6 @@ public class Warn extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
String defaultReason = templateService.renderSimpleTemplate(WARN_DEFAULT_REASON_TEMPLATE); String defaultReason = templateService.renderSimpleTemplate(WARN_DEFAULT_REASON_TEMPLATE);

View File

@@ -52,7 +52,6 @@ public class Warnings extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Warning> warnsToDisplay; List<Warning> warnsToDisplay;
if(!commandContext.getParameters().getParameters().isEmpty()) { if(!commandContext.getParameters().getParameters().isEmpty()) {
Member member = (Member) commandContext.getParameters().getParameters().get(0); Member member = (Member) commandContext.getParameters().getParameters().get(0);

View File

@@ -31,7 +31,6 @@ public class Mute extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
Duration duration = (Duration) parameters.get(1); Duration duration = (Duration) parameters.get(1);

View File

@@ -30,7 +30,6 @@ public class SetMuteRole extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Role jdaRole = (Role) commandContext.getParameters().getParameters().get(0); Role jdaRole = (Role) commandContext.getParameters().getParameters().get(0);
ARole role = roleManagementService.findRole(jdaRole.getIdLong()); ARole role = roleManagementService.findRole(jdaRole.getIdLong());
muteRoleManagementService.setMuteRoleForServer(commandContext.getUserInitiatedContext().getServer(), role); muteRoleManagementService.setMuteRoleForServer(commandContext.getUserInitiatedContext().getServer(), role);

View File

@@ -39,7 +39,6 @@ public class UnMute extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member member = (Member) parameters.get(0); Member member = (Member) parameters.get(0);
AUserInAServer userToUnMute = userInServerManagementService.loadUser(member); AUserInAServer userToUnMute = userInServerManagementService.loadUser(member);

View File

@@ -1,6 +1,6 @@
package dev.sheldan.abstracto.moderation.service; package dev.sheldan.abstracto.moderation.service;
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException; import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
import dev.sheldan.abstracto.core.models.database.AChannel; import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.service.BotService; import dev.sheldan.abstracto.core.service.BotService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -41,7 +41,7 @@ public class SlowModeServiceBean implements SlowModeService {
TextChannel textChannel = textChannelOptional.get(); TextChannel textChannel = textChannelOptional.get();
return this.setSlowMode(textChannel, duration); return this.setSlowMode(textChannel, duration);
} else { } else {
throw new ChannelNotFoundException(channel.getId()); throw new ChannelNotInGuildException(channel.getId());
} }
} }
} }

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.models.template.commands.BanIdLog; import dev.sheldan.abstracto.moderation.models.template.commands.BanIdLog;
@@ -69,18 +67,6 @@ public class BanIdTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.models.template.commands.BanLog; import dev.sheldan.abstracto.moderation.models.template.commands.BanLog;
@@ -68,16 +66,6 @@ public class BanTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ResultState; import dev.sheldan.abstracto.core.command.execution.ResultState;
@@ -53,16 +51,6 @@ public class DeleteNoteTest {
Assert.assertNotNull(result.getMessage()); Assert.assertNotNull(result.getMessage());
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AServer; import dev.sheldan.abstracto.core.models.database.AServer;
@@ -52,17 +50,6 @@ public class DeleteWarningTest {
CommandTestUtilities.checkSuccessfulCompletion(result); CommandTestUtilities.checkSuccessfulCompletion(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel; import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel;
@@ -70,17 +68,6 @@ public class KickTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ResultState; import dev.sheldan.abstracto.core.command.execution.ResultState;
@@ -54,16 +52,6 @@ public class PurgeTest {
Assert.assertEquals(ResultState.SELF_DESTRUCT, result.join().getResult()); Assert.assertEquals(ResultState.SELF_DESTRUCT, result.join().getResult());
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.service.SlowModeService; import dev.sheldan.abstracto.moderation.service.SlowModeService;
@@ -68,16 +66,6 @@ public class SlowModeTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AServer; import dev.sheldan.abstracto.core.models.database.AServer;
@@ -47,11 +46,6 @@ public class UserNoteCommandTest {
CommandTestUtilities.checkSuccessfulCompletion(result); CommandTestUtilities.checkSuccessfulCompletion(result);
} }
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer; import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -106,11 +105,6 @@ public class UserNotesTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands; package dev.sheldan.abstracto.moderation.commands;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.models.template.commands.WarnContext; import dev.sheldan.abstracto.moderation.models.template.commands.WarnContext;
@@ -66,16 +64,6 @@ public class WarnTest {
CommandTestUtilities.checkSuccessfulCompletionAsync(result); CommandTestUtilities.checkSuccessfulCompletionAsync(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.moderation.commands;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jdautilities.menu.Paginator; import com.jagrosh.jdautilities.menu.Paginator;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer; import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -108,11 +107,6 @@ public class WarningsTest {
} }
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands.mute; package dev.sheldan.abstracto.moderation.commands.mute;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.moderation.models.template.commands.MuteContext; import dev.sheldan.abstracto.moderation.models.template.commands.MuteContext;
@@ -47,16 +45,6 @@ public class MuteTest {
Assert.assertEquals(parameters.getAuthor(), muteLog.getMutingUser()); Assert.assertEquals(parameters.getAuthor(), muteLog.getMutingUser());
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands.mute; package dev.sheldan.abstracto.moderation.commands.mute;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole; import dev.sheldan.abstracto.core.models.database.ARole;
@@ -46,16 +44,6 @@ public class SetMuteRoleTest {
CommandTestUtilities.checkSuccessfulCompletion(result); CommandTestUtilities.checkSuccessfulCompletion(result);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.moderation.commands.mute; package dev.sheldan.abstracto.moderation.commands.mute;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer; import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -65,16 +63,6 @@ public class UnMuteTest {
testUnit.executeAsync(parameters); testUnit.executeAsync(parameters);
} }
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void validateCommand() { public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration()); CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());

View File

@@ -22,8 +22,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import static dev.sheldan.abstracto.core.test.MockUtils.mockQueueDoubleVoidConsumer;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
@@ -114,7 +114,7 @@ public class PurgeServiceBeanTest {
setupFirstMessageHistoryMocks(); setupFirstMessageHistoryMocks();
setupStatusMessageMocks(); setupStatusMessageMocks();
mockConsumer(deleteMessagesAction); mockQueueDoubleVoidConsumer(deleteMessagesAction);
CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, null); CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, null);
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable)); futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS); verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
@@ -136,7 +136,7 @@ public class PurgeServiceBeanTest {
setupStatusMessageMocks(); setupStatusMessageMocks();
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class); AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
when(firstMessage.delete()).thenReturn(auditableRestAction); when(firstMessage.delete()).thenReturn(auditableRestAction);
mockConsumer(auditableRestAction); mockQueueDoubleVoidConsumer(auditableRestAction);
CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, purgedMember); CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, purgedMember);
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable)); futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS); verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
@@ -194,7 +194,7 @@ public class PurgeServiceBeanTest {
when(textChannel.deleteMessages(secondMessagesToDelete)).thenReturn(secondDeleteMessagesAction); when(textChannel.deleteMessages(secondMessagesToDelete)).thenReturn(secondDeleteMessagesAction);
mockConsumer(secondDeleteMessagesAction); mockQueueDoubleVoidConsumer(secondDeleteMessagesAction);
CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, purgedMember); CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, purgedMember);
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable)); futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS); verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
@@ -233,7 +233,7 @@ public class PurgeServiceBeanTest {
setupFirstMessages(firstMessage, deletableMessageId, secondMessage, deletableMessageId2, messageAuthor); setupFirstMessages(firstMessage, deletableMessageId, secondMessage, deletableMessageId2, messageAuthor);
setupMembersWithAuthorId(); setupMembersWithAuthorId();
setupFirstMessageHistoryMocks(); setupFirstMessageHistoryMocks();
mockConsumer(deleteMessagesAction); mockQueueDoubleVoidConsumer(deleteMessagesAction);
setupStatusMessageMocks(); setupStatusMessageMocks();
} }
@@ -261,16 +261,7 @@ public class PurgeServiceBeanTest {
when(secondMessageToMock.getAuthor()).thenReturn(author); when(secondMessageToMock.getAuthor()).thenReturn(author);
} }
private void mockConsumer(RestAction secondDeleteMessagesAction) {
doAnswer(invocationOnMock -> {
Object consumerObj = invocationOnMock.getArguments()[0];
if(consumerObj instanceof Consumer) {
Consumer<Void> consumer = (Consumer) consumerObj;
consumer.accept(null);
}
return null;
}).when(secondDeleteMessagesAction).queue(any(Consumer.class), any(Consumer.class));
}
private Long getDeletableMessageId() { private Long getDeletableMessageId() {
return TimeUtil.getDiscordTimestamp((System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000))); return TimeUtil.getDiscordTimestamp((System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000)));

View File

@@ -1,6 +1,6 @@
package dev.sheldan.abstracto.moderation.service; package dev.sheldan.abstracto.moderation.service;
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException; import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
import dev.sheldan.abstracto.core.models.database.AChannel; import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer; import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.BotService; import dev.sheldan.abstracto.core.service.BotService;
@@ -79,7 +79,7 @@ public class SlowModeServiceBeanTest {
testUnit.setSlowMode(channel, duration); testUnit.setSlowMode(channel, duration);
} }
@Test(expected = ChannelNotFoundException.class) @Test(expected = ChannelNotInGuildException.class)
public void testSlowModeInAChannelNotFound() { public void testSlowModeInAChannelNotFound() {
AServer server = MockUtils.getServer(); AServer server = MockUtils.getServer();
AChannel aChannel = MockUtils.getTextChannel(server, 5L); AChannel aChannel = MockUtils.getTextChannel(server, 5L);

View File

@@ -32,7 +32,6 @@ public class DeleteTrackedEmote extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0); TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
// need to actually load the TrackedEmote // need to actually load the TrackedEmote

View File

@@ -43,7 +43,6 @@ public class DeletedEmoteStats extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
// default is 1.1.1970 // default is 1.1.1970
Instant statsSince = Instant.EPOCH; Instant statsSince = Instant.EPOCH;

View File

@@ -32,7 +32,6 @@ public class DisableEmoteTracking extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
if(!parameters.isEmpty()) { if(!parameters.isEmpty()) {
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0); TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);

View File

@@ -44,7 +44,6 @@ public class EmoteStats extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
// default is 1.1.1970 // default is 1.1.1970
Instant statsSince = Instant.EPOCH; Instant statsSince = Instant.EPOCH;

View File

@@ -65,7 +65,6 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Instant statsSince = Instant.EPOCH; Instant statsSince = Instant.EPOCH;
// default is 1.1.1970 // default is 1.1.1970

View File

@@ -46,7 +46,6 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
// default is 1.1.1970 // default is 1.1.1970
Instant statsSince = Instant.EPOCH; Instant statsSince = Instant.EPOCH;

View File

@@ -35,7 +35,6 @@ public class PurgeEmoteStats extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0); TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId()); TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId());

View File

@@ -40,7 +40,6 @@ public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0); TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
// load the actual TrackedEmote instance // load the actual TrackedEmote instance

View File

@@ -50,7 +50,6 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
// per default, do not show TrackedEmote for which tracking has been disabled // per default, do not show TrackedEmote for which tracking has been disabled
Boolean showTrackingDisabled = false; Boolean showTrackingDisabled = false;

View File

@@ -44,7 +44,6 @@ public class TrackEmote extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
TrackEmoteParameter emoteToTrack = (TrackEmoteParameter) commandContext.getParameters().getParameters().get(0); TrackEmoteParameter emoteToTrack = (TrackEmoteParameter) commandContext.getParameters().getParameters().get(0);
Long emoteId = emoteToTrack.getTrackedEmote().getTrackedEmoteId().getId(); Long emoteId = emoteToTrack.getTrackedEmote().getTrackedEmoteId().getId();
long serverId = commandContext.getGuild().getIdLong(); long serverId = commandContext.getGuild().getIdLong();

View File

@@ -1,9 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.ServerSpecificId; import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException; import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException;
@@ -34,16 +33,6 @@ public class DeleteTrackedEmoteTest {
@Mock @Mock
private TrackedEmoteService trackedEmoteService; private TrackedEmoteService trackedEmoteService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testExecuteWithExistingTrackedEmote() { public void testExecuteWithExistingTrackedEmote() {
TrackedEmote fakedEmote = Mockito.mock(TrackedEmote.class); TrackedEmote fakedEmote = Mockito.mock(TrackedEmote.class);
@@ -69,4 +58,10 @@ public class DeleteTrackedEmoteTest {
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel; import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class DeletedEmoteStatsTest {
@Mock @Mock
private ChannelService channelService; private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testWithoutParameterStaticEmotes() { public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -94,4 +89,9 @@ public class DeletedEmoteStatsTest {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.models.ServerSpecificId; import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote; import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
@@ -32,11 +32,6 @@ public class DisableEmoteTrackingTest {
@Mock @Mock
private TrackedEmoteManagementService trackedEmoteManagementService; private TrackedEmoteManagementService trackedEmoteManagementService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testDisableAllTracking() { public void testDisableAllTracking() {
CommandContext commandContext = CommandTestUtilities.getNoParameters(); CommandContext commandContext = CommandTestUtilities.getNoParameters();
@@ -60,4 +55,10 @@ public class DisableEmoteTrackingTest {
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel; import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class EmoteStatsTest {
@Mock @Mock
private ChannelService channelService; private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testWithoutParameterStaticEmotes() { public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -93,4 +88,10 @@ public class EmoteStatsTest {
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,12 +1,12 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException; import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AServer; import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService; import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.core.utils.FileUtils; import dev.sheldan.abstracto.core.utils.FileUtils;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
@@ -67,10 +67,6 @@ public class ExportEmoteStatsTest {
private static final String FILE_NAME = "name"; private static final String FILE_NAME = "name";
private static final String FILE_CONTENT = "content"; private static final String FILE_CONTENT = "content";
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testExportAllEmoteStats() throws IOException { public void testExportAllEmoteStats() throws IOException {
@@ -176,4 +172,10 @@ public class ExportEmoteStatsTest {
when(templateService.renderTemplate(eq(DOWNLOAD_EMOTE_STATS_FILE_NAME_TEMPLATE_KEY), modelArgumentCaptor.capture())).thenReturn(FILE_NAME); when(templateService.renderTemplate(eq(DOWNLOAD_EMOTE_STATS_FILE_NAME_TEMPLATE_KEY), modelArgumentCaptor.capture())).thenReturn(FILE_NAME);
when(templateService.renderTemplate(eq(DOWNLOAD_EMOTE_STATS_FILE_CONTENT_TEMPLATE_KEY), any())).thenReturn(FILE_CONTENT); when(templateService.renderTemplate(eq(DOWNLOAD_EMOTE_STATS_FILE_CONTENT_TEMPLATE_KEY), any())).thenReturn(FILE_CONTENT);
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel; import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class ExternalEmoteStatsTest {
@Mock @Mock
private ChannelService channelService; private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testWithoutParameterStaticEmotes() { public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters(); CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -93,4 +88,10 @@ public class ExternalEmoteStatsTest {
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.models.ServerSpecificId; import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote; import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
@@ -34,11 +34,6 @@ public class PurgeEmoteStatsTest {
@Mock @Mock
private UsedEmoteService usedEmoteService; private UsedEmoteService usedEmoteService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testPurgeEntireTimeLineOfEmote() { public void testPurgeEntireTimeLineOfEmote() {
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class); TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
@@ -63,10 +58,15 @@ public class PurgeEmoteStatsTest {
verify(usedEmoteService, times(1)).purgeEmoteUsagesSince(eq(actualTrackedEmote), any(Instant.class)); verify(usedEmoteService, times(1)).purgeEmoteUsagesSince(eq(actualTrackedEmote), any(Instant.class));
} }
@Test @Test
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,12 +1,11 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException; import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.ServerSpecificId; import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode; import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
@@ -38,16 +37,6 @@ public class ShowExternalTrackedEmoteTest {
@Mock @Mock
private TrackedEmoteManagementService trackedEmoteManagementService; private TrackedEmoteManagementService trackedEmoteManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testShowExternalEmote() { public void testShowExternalEmote() {
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class); TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
@@ -84,4 +73,10 @@ public class ShowExternalTrackedEmoteTest {
public void testFeatureModeLimitations() { public void testFeatureModeLimitations() {
Assert.assertTrue(testUnit.getFeatureModeLimitations().contains(EmoteTrackingMode.EXTERNAL_EMOTES)); Assert.assertTrue(testUnit.getFeatureModeLimitations().contains(EmoteTrackingMode.EXTERNAL_EMOTES));
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,10 +1,10 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.ChannelService; import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.FeatureModeService; import dev.sheldan.abstracto.core.service.FeatureModeService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode; import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
@@ -45,11 +45,6 @@ public class ShowTrackedEmotesTest {
private static final Long SERVER_ID = 4L; private static final Long SERVER_ID = 4L;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test @Test
public void testShowTrackedEmotesNoStats() { public void testShowTrackedEmotesNoStats() {
CommandContext commandContext = CommandTestUtilities.getNoParameters(); CommandContext commandContext = CommandTestUtilities.getNoParameters();
@@ -230,4 +225,10 @@ public class ShowTrackedEmotesTest {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -1,14 +1,13 @@
package dev.sheldan.abstracto.statistic.emotes.command; package dev.sheldan.abstracto.statistic.emotes.command;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterException; import dev.sheldan.abstracto.core.command.exception.IncorrectParameterException;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
import dev.sheldan.abstracto.core.command.execution.CommandContext; import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult; import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.exception.IncorrectFeatureModeException; import dev.sheldan.abstracto.core.command.exception.IncorrectFeatureModeException;
import dev.sheldan.abstracto.core.models.ServerSpecificId; import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.service.EmoteService; import dev.sheldan.abstracto.core.service.EmoteService;
import dev.sheldan.abstracto.core.service.FeatureModeService; import dev.sheldan.abstracto.core.service.FeatureModeService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities; import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures; import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter; import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter;
@@ -53,16 +52,6 @@ public class TrackEmoteTest {
private static final Long EMOTE_ID = 4L; private static final Long EMOTE_ID = 4L;
private static final Long SERVER_ID = 5L; private static final Long SERVER_ID = 5L;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test @Test
public void testReTrackTrackedEmote(){ public void testReTrackTrackedEmote(){
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(trackEmoteParameter)); CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(trackEmoteParameter));
@@ -124,4 +113,10 @@ public class TrackEmoteTest {
public void testFeature() { public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature()); Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
} }
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
} }

View File

@@ -32,7 +32,6 @@ public class ShowAvatar extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getUserInitiatedContext().getMember(); Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getUserInitiatedContext().getMember();
ShowAvatarModel model = (ShowAvatarModel) ContextConverter.fromCommandContext(commandContext, ShowAvatarModel.class); ShowAvatarModel model = (ShowAvatarModel) ContextConverter.fromCommandContext(commandContext, ShowAvatarModel.class);

View File

@@ -29,7 +29,6 @@ public class ShowEmote extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Emote emoteParameter = (Emote) parameters.get(0); Emote emoteParameter = (Emote) parameters.get(0);
ShowEmoteLog emoteLog = (ShowEmoteLog) ContextConverter.fromCommandContext(commandContext, ShowEmoteLog.class); ShowEmoteLog emoteLog = (ShowEmoteLog) ContextConverter.fromCommandContext(commandContext, ShowEmoteLog.class);

View File

@@ -39,7 +39,6 @@ public class UserInfo extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getAuthor(); Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getAuthor();
UserInfoModel model = (UserInfoModel) ContextConverter.slimFromCommandContext(commandContext, UserInfoModel.class); UserInfoModel model = (UserInfoModel) ContextConverter.slimFromCommandContext(commandContext, UserInfoModel.class);

View File

@@ -37,7 +37,6 @@ public class Remind extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Duration remindTime = (Duration) parameters.get(0); Duration remindTime = (Duration) parameters.get(0);
String text = (String) parameters.get(1); String text = (String) parameters.get(1);

View File

@@ -29,7 +29,6 @@ public class UnRemind extends AbstractConditionableCommand {
@Override @Override
public CommandResult execute(CommandContext commandContext) { public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
Long reminderId = (Long) commandContext.getParameters().getParameters().get(0); Long reminderId = (Long) commandContext.getParameters().getParameters().get(0);
reminderService.unRemind(reminderId, commandContext.getUserInitiatedContext().getAUserInAServer()); reminderService.unRemind(reminderId, commandContext.getUserInitiatedContext().getAUserInAServer());
return CommandResult.fromSuccess(); return CommandResult.fromSuccess();

View File

@@ -0,0 +1,67 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ChannelGroupManagementService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.service.RepostCheckChannelService;
import dev.sheldan.abstracto.utility.service.RepostServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class DisableRepostCheck extends AbstractConditionableCommand {
@Autowired
private RepostCheckChannelService repostCheckChannelService;
@Autowired
private ChannelGroupManagementService channelGroupManagementService;
@Autowired
private ServerManagementService serverManagementService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
AChannelGroup fakeChannelGroup = (AChannelGroup) parameters.get(0);
AServer actualServer = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
AChannelGroup actualChannelGroup = channelGroupManagementService.findByNameAndServerAndType(fakeChannelGroup.getGroupName(), actualServer, RepostServiceBean.REPOST_CHECK_CHANNEL_GROUP_TYPE);
repostCheckChannelService.setRepostCheckDisabledForChannelGroup(actualChannelGroup);
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelToSet = Parameter.builder().name("channelGroup").type(AChannelGroup.class).templated(true).build();
List<Parameter> parameters = Arrays.asList(channelToSet);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("disableRepostCheck")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(false)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
}

View File

@@ -0,0 +1,67 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ChannelGroupManagementService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.service.RepostCheckChannelService;
import dev.sheldan.abstracto.utility.service.RepostServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class EnableRepostCheck extends AbstractConditionableCommand {
@Autowired
private RepostCheckChannelService repostCheckChannelService;
@Autowired
private ChannelGroupManagementService channelGroupManagementService;
@Autowired
private ServerManagementService serverManagementService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
AChannelGroup fakeChannelGroup = (AChannelGroup) parameters.get(0);
AServer actualServer = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
AChannelGroup actualChannelGroup = channelGroupManagementService.findByNameAndServerAndType(fakeChannelGroup.getGroupName(), actualServer, RepostServiceBean.REPOST_CHECK_CHANNEL_GROUP_TYPE);
repostCheckChannelService.setRepostCheckEnabledForChannelGroup(actualChannelGroup);
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelToSet = Parameter.builder().name("channelGroup").type(AChannelGroup.class).templated(true).build();
List<Parameter> parameters = Arrays.asList(channelToSet);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("enableRepostCheck")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(false)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
}

View File

@@ -0,0 +1,64 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.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.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.service.PostedImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class PurgeImagePosts extends AbstractConditionableCommand {
@Autowired
private PostedImageService postedImageService;
@Autowired
private UserInServerManagementService userInServerManagementService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
if(!parameters.isEmpty()) {
AUserInAServer fakeUser = (AUserInAServer) parameters.get(0);
AUserInAServer actualUser = userInServerManagementService.loadUser(fakeUser.getUserInServerId());
postedImageService.purgePostedImages(actualUser);
} else {
postedImageService.purgePostedImages(commandContext.getGuild());
}
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelToSet = Parameter.builder().name("member").type(AUserInAServer.class).templated(true).optional(true).build();
List<Parameter> parameters = Arrays.asList(channelToSet);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("purgeImagePosts")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(false)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
}

View File

@@ -0,0 +1,64 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.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.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.service.RepostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class PurgeReposts extends AbstractConditionableCommand {
@Autowired
private UserInServerManagementService userInServerManagementService;
@Autowired
private RepostService repostService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
if(!parameters.isEmpty()) {
AUserInAServer fakeUser = (AUserInAServer) parameters.get(0);
AUserInAServer actualUser = userInServerManagementService.loadUser(fakeUser.getUserInServerId());
repostService.purgeReposts(actualUser);
} else {
repostService.purgeReposts(commandContext.getGuild());
}
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelToSet = Parameter.builder().name("member").type(AUserInAServer.class).templated(true).optional(true).build();
List<Parameter> parameters = Arrays.asList(channelToSet);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("purgeReposts")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(false)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
}

View File

@@ -0,0 +1,102 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.RepostDetectionFeatureMode;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.converter.RepostLeaderBoardConverter;
import dev.sheldan.abstracto.utility.models.RepostLeaderboardEntryModel;
import dev.sheldan.abstracto.utility.models.RepostLeaderboardModel;
import dev.sheldan.abstracto.utility.models.database.result.RepostLeaderboardResult;
import dev.sheldan.abstracto.utility.service.RepostService;
import dev.sheldan.abstracto.utility.service.management.RepostManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class RepostLeaderboard extends AbstractConditionableCommand {
public static final String REPOST_LEADERBOARD_RESPONSE_TEMPLATE_KEY = "repostLeaderboard_response";
@Autowired
private RepostService repostService;
@Autowired
private RepostManagementService repostManagementService;
@Autowired
private TemplateService templateService;
@Autowired
private ChannelService channelService;
@Autowired
private RepostLeaderBoardConverter converter;
@Autowired
private UserInServerManagementService userInServerManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 1;
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(commandContext.getAuthor());
List<RepostLeaderboardResult> topRepostingUsersOfServer = repostManagementService.findTopRepostingUsersOfServer(commandContext.getGuild().getIdLong(), page, 5);
RepostLeaderboardResult resultOfUser = repostManagementService.getRepostRankOfUser(aUserInAServer);
CompletableFuture<List<RepostLeaderboardEntryModel>> leaderBoardFuture = converter.fromLeaderBoardResults(topRepostingUsersOfServer);
CompletableFuture<RepostLeaderboardEntryModel> userFuture = converter.convertSingleUser(resultOfUser);
return CompletableFuture.allOf(leaderBoardFuture, userFuture).thenCompose(unused -> {
List<RepostLeaderboardEntryModel> entries = leaderBoardFuture.join();
RepostLeaderboardModel model = RepostLeaderboardModel
.builder()
.guild(commandContext.getGuild())
.entries(entries)
.userExecuting(userFuture.join())
.member(commandContext.getAuthor())
.build();
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(REPOST_LEADERBOARD_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()));
}).thenApply(o -> CommandResult.fromIgnored());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter channelToSet = Parameter.builder().name("page").type(Integer.class).templated(true).optional(true).build();
List<Parameter> parameters = Arrays.asList(channelToSet);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("repostLeaderboard")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
@Override
public List<FeatureMode> getFeatureModeLimitations() {
return Arrays.asList(RepostDetectionFeatureMode.LEADERBOARD);
}
}

View File

@@ -0,0 +1,62 @@
package dev.sheldan.abstracto.utility.commands.repost;
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.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.utility.config.RepostDetectionModuleInterface;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.converter.RepostCheckChannelModelConverter;
import dev.sheldan.abstracto.utility.models.database.RepostCheckChannelGroup;
import dev.sheldan.abstracto.utility.models.template.commands.RepostCheckChannelsModel;
import dev.sheldan.abstracto.utility.service.RepostCheckChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class ShowRepostCheckChannels extends AbstractConditionableCommand {
public static final String SHOW_REPOST_CHECK_CHANNELS_RESPONSE_TEMPLATE_KEY = "showRepostCheckChannels_response";
@Autowired
private RepostCheckChannelModelConverter converter;
@Autowired
private RepostCheckChannelService checkChannelService;
@Autowired
private ChannelService channelService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<RepostCheckChannelGroup> channelGroups = checkChannelService.getChannelGroupsWithEnabledCheck(commandContext.getGuild().getIdLong());
RepostCheckChannelsModel model = converter.fromRepostCheckChannelGroups(channelGroups, commandContext.getGuild());
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SHOW_REPOST_CHECK_CHANNELS_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
.thenApply(unused -> CommandResult.fromIgnored());
}
@Override
public CommandConfiguration getConfiguration() {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("showRepostCheckChannels")
.module(RepostDetectionModuleInterface.REPOST_DETECTION)
.templated(true)
.async(true)
.supportsEmbedException(true)
.causesReaction(false)
.help(helpInfo)
.build();
}
@Override
public FeatureEnum getFeature() {
return UtilityFeature.REPOST_DETECTION;
}
}

View File

@@ -30,7 +30,6 @@ public class Accept extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Long suggestionId = (Long) parameters.get(0); Long suggestionId = (Long) parameters.get(0);
String text = parameters.size() == 2 ? (String) parameters.get(1) : ""; String text = parameters.size() == 2 ? (String) parameters.get(1) : "";

View File

@@ -30,7 +30,6 @@ public class Reject extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
Long suggestionId = (Long) parameters.get(0); Long suggestionId = (Long) parameters.get(0);
String text = parameters.size() == 2 ? (String) parameters.get(1) : ""; String text = parameters.size() == 2 ? (String) parameters.get(1) : "";

View File

@@ -25,7 +25,6 @@ public class Suggest extends AbstractConditionableCommand {
@Override @Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) { public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
checkParameters(commandContext);
List<Object> parameters = commandContext.getParameters().getParameters(); List<Object> parameters = commandContext.getParameters().getParameters();
String text = (String) parameters.get(0); String text = (String) parameters.get(0);
SuggestionLog suggestLogModel = (SuggestionLog) ContextConverter.fromCommandContext(commandContext, SuggestionLog.class); SuggestionLog suggestLogModel = (SuggestionLog) ContextConverter.fromCommandContext(commandContext, SuggestionLog.class);

View File

@@ -0,0 +1,42 @@
package dev.sheldan.abstracto.utility.converter;
import dev.sheldan.abstracto.core.models.FullChannel;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.utility.models.database.RepostCheckChannelGroup;
import dev.sheldan.abstracto.utility.models.template.commands.RepostCheckChannelGroupDisplayModel;
import dev.sheldan.abstracto.utility.models.template.commands.RepostCheckChannelsModel;
import net.dv8tion.jda.api.entities.Guild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class RepostCheckChannelModelConverter {
@Autowired
private BotService botService;
public RepostCheckChannelsModel fromRepostCheckChannelGroups(List<RepostCheckChannelGroup> channelGroups, Guild guild) {
List<RepostCheckChannelGroupDisplayModel> repostCheckChannelGroups = new ArrayList<>();
channelGroups.forEach(repostCheckChannelGroup -> {
List<FullChannel> fullChannels = repostCheckChannelGroup.getChannelGroup().getChannels().stream().map(channel ->
FullChannel
.builder()
.channel(channel)
.serverChannel(botService.getTextChannelFromServerNullable(guild, channel.getId()))
.build()
).collect(Collectors.toList());
repostCheckChannelGroups.add(
RepostCheckChannelGroupDisplayModel
.builder()
.channelGroup(repostCheckChannelGroup)
.channels(fullChannels)
.build());
});
return RepostCheckChannelsModel.builder().repostCheckChannelGroups(repostCheckChannelGroups).build();
}
}

View File

@@ -0,0 +1,62 @@
package dev.sheldan.abstracto.utility.converter;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.utility.models.RepostLeaderboardEntryModel;
import dev.sheldan.abstracto.utility.models.database.result.RepostLeaderboardResult;
import net.dv8tion.jda.api.entities.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Component
public class RepostLeaderBoardConverter {
@Autowired
private UserInServerManagementService userInServerManagementService;
@Autowired
private BotService botService;
@Autowired
private RepostLeaderBoardConverter self;
public CompletableFuture<List<RepostLeaderboardEntryModel>> fromLeaderBoardResults(List<RepostLeaderboardResult> results) {
if(results.isEmpty()) {
return CompletableFuture.completedFuture(new ArrayList<>());
}
List<CompletableFuture<RepostLeaderboardEntryModel>> modelFutures =
results.stream().map(this::convertSingleUser).collect(Collectors.toList());
return FutureUtils.toSingleFutureGeneric(modelFutures).thenApply(unused ->
modelFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())
);
}
public CompletableFuture<RepostLeaderboardEntryModel> convertSingleUser(RepostLeaderboardResult result) {
AUserInAServer user = userInServerManagementService.loadUser(result.getUserInServerId());
Integer count = result.getRepostCount();
Long userInServerId = result.getUserInServerId();
Integer rank = result.getRank();
return botService.getMemberInServerAsync(user).thenApply(member ->
self.loadUserFromDatabase(member, count, userInServerId, rank)
);
}
@Transactional
public RepostLeaderboardEntryModel loadUserFromDatabase(Member member, Integer count, Long userInServerId, Integer rank) {
return RepostLeaderboardEntryModel
.builder()
.member(member)
.user(userInServerManagementService.loadUser(userInServerId))
.count(count)
.rank(rank)
.build();
}
}

Some files were not shown because too many files have changed in this diff Show More