[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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,8 @@
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.models.ServerSpecificId;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException;
@@ -34,16 +33,6 @@ public class DeleteTrackedEmoteTest {
@Mock
private TrackedEmoteService trackedEmoteService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test
public void testExecuteWithExistingTrackedEmote() {
TrackedEmote fakedEmote = Mockito.mock(TrackedEmote.class);
@@ -69,4 +58,10 @@ public class DeleteTrackedEmoteTest {
public void testFeature() {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class DeletedEmoteStatsTest {
@Mock
private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -94,4 +89,9 @@ public class DeletedEmoteStatsTest {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
@@ -32,11 +32,6 @@ public class DisableEmoteTrackingTest {
@Mock
private TrackedEmoteManagementService trackedEmoteManagementService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test
public void testDisableAllTracking() {
CommandContext commandContext = CommandTestUtilities.getNoParameters();
@@ -60,4 +55,10 @@ public class DisableEmoteTrackingTest {
public void testFeature() {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class EmoteStatsTest {
@Mock
private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -93,4 +88,10 @@ public class EmoteStatsTest {
public void testFeature() {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.ChannelService;
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.utils.FileUtils;
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_CONTENT = "content";
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
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_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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
@@ -38,11 +38,6 @@ public class ExternalEmoteStatsTest {
@Mock
private ChannelService channelService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
public void testWithoutParameterStaticEmotes() {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
@@ -93,4 +88,10 @@ public class ExternalEmoteStatsTest {
public void testFeature() {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
@@ -34,11 +34,6 @@ public class PurgeEmoteStatsTest {
@Mock
private UsedEmoteService usedEmoteService;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test
public void testPurgeEntireTimeLineOfEmote() {
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
@@ -63,10 +58,15 @@ public class PurgeEmoteStatsTest {
verify(usedEmoteService, times(1)).purgeEmoteUsagesSince(eq(actualTrackedEmote), any(Instant.class));
}
@Test
public void testFeature() {
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;
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.CommandResult;
import dev.sheldan.abstracto.core.models.ServerSpecificId;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
@@ -38,16 +37,6 @@ public class ShowExternalTrackedEmoteTest {
@Mock
private TrackedEmoteManagementService trackedEmoteManagementService;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTestAsync(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
public void testShowExternalEmote() {
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
@@ -84,4 +73,10 @@ public class ShowExternalTrackedEmoteTest {
public void testFeatureModeLimitations() {
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;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeException;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.ChannelService;
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.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
@@ -45,11 +45,6 @@ public class ShowTrackedEmotesTest {
private static final Long SERVER_ID = 4L;
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTestAsync(testUnit);
}
@Test
public void testShowTrackedEmotesNoStats() {
CommandContext commandContext = CommandTestUtilities.getNoParameters();
@@ -230,4 +225,10 @@ public class ShowTrackedEmotesTest {
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;
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.CommandResult;
import dev.sheldan.abstracto.core.command.exception.IncorrectFeatureModeException;
import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.service.EmoteService;
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.statistic.config.StatisticFeatures;
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 SERVER_ID = 5L;
@Test(expected = InsufficientParametersException.class)
public void testTooLittleParameters() {
CommandTestUtilities.executeNoParametersTest(testUnit);
}
@Test(expected = IncorrectParameterTypeException.class)
public void testIncorrectParameterType() {
CommandTestUtilities.executeWrongParametersTest(testUnit);
}
@Test
public void testReTrackTrackedEmote(){
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(trackEmoteParameter));
@@ -124,4 +113,10 @@ public class TrackEmoteTest {
public void testFeature() {
Assert.assertEquals(StatisticFeatures.EMOTE_TRACKING, testUnit.getFeature());
}
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
}