[AB-77] moving the templating module into the core module

adding a possibility to overlay specific templates for particular servers
adding commands to configure templates
adding file parameter support
This commit is contained in:
Sheldan
2021-02-19 16:27:27 +01:00
parent 909dc87d94
commit 43eca33113
361 changed files with 2158 additions and 2591 deletions

View File

@@ -62,17 +62,17 @@ public class DeletedEmoteStats extends AbstractConditionableCommand {
// only show the embed, if there are static emotes to show
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
log.trace("Deleted emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// only show the embed, if there are animated emotes to show
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
log.trace("Deleted emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// if neither static nor animated emote stats are available, show an embed indicating so
if(!emoteStatsModel.areStatsAvailable()) {
log.info("No delete emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
}
return FutureUtils.toSingleFutureGeneric(messagePromises)

View File

@@ -63,17 +63,17 @@ public class EmoteStats extends AbstractConditionableCommand {
// only show embed if static emote stats are available
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
log.trace("Emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// only show embed if animated emote stats are available
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
log.trace("Emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// show an embed if no emote stats are available indicating so
if(!emoteStatsModel.areStatsAvailable()) {
log.info("No emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
}
return FutureUtils.toSingleFutureGeneric(messagePromises)

View File

@@ -8,19 +8,19 @@ 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.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.exception.UploadFileTooLargeException;
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.utils.FileUtils;
import dev.sheldan.abstracto.core.utils.FileService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
import dev.sheldan.abstracto.statistic.emotes.exception.DownloadEmoteStatsFileTooBigException;
import dev.sheldan.abstracto.statistic.emotes.model.DownloadEmoteStatsModel;
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -37,7 +37,7 @@ import java.util.concurrent.CompletableFuture;
/**
* This command renders a file containing information about emote statistics and provides the file as a download.
* If the file size is over the size limit of the {@link net.dv8tion.jda.api.entities.Guild}, this command will fail, but
* throw an {@link DownloadEmoteStatsFileTooBigException}.
* throw an {@link UploadFileTooLargeException}.
* This will create a temporary file on the server, which will be deleted after it has been send.
*/
@Component
@@ -61,7 +61,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
private UsedEmoteManagementService usedEmoteManagementService;
@Autowired
private FileUtils fileUtils;
private FileService fileService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
@@ -77,7 +77,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
List<UsedEmote> usedEmotes = usedEmoteManagementService.loadEmoteUsagesForServerSince(actualServer, statsSince);
// if there are no stats available, render a message indicating so
if(usedEmotes.isEmpty()) {
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY, new Object(), commandContext.getChannel()))
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY, new Object(), commandContext.getChannel()))
.thenApply(unused -> CommandResult.fromIgnored());
}
// info might not be nice to handle in the template, and 1970 would look weird to users
@@ -93,13 +93,13 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
.build();
String fileName = templateService.renderTemplate(DOWNLOAD_EMOTE_STATS_FILE_NAME_TEMPLATE_KEY, model);
String fileContent = templateService.renderTemplate(DOWNLOAD_EMOTE_STATS_FILE_CONTENT_TEMPLATE_KEY, model);
File tempFile = fileUtils.createTempFile(fileName);
File tempFile = fileService.createTempFile(fileName);
try {
fileUtils.writeContentToFile(tempFile, fileContent);
fileService.writeContentToFile(tempFile, fileContent);
long maxFileSize = commandContext.getGuild().getMaxFileSize();
// in this case, we cannot upload the file, so we need to fail
if(maxFileSize < tempFile.length()) {
throw new DownloadEmoteStatsFileTooBigException(tempFile.length(), maxFileSize);
if(tempFile.length() > maxFileSize) {
throw new UploadFileTooLargeException(tempFile.length(), maxFileSize);
}
MessageToSend messageToSend = templateService.renderEmbedTemplate(DOWNLOAD_EMOTE_STATS_RESPONSE_TEMPLATE_KEY, model);
messageToSend.setFileToSend(tempFile);
@@ -109,7 +109,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
throw new AbstractoRunTimeException(e);
} finally {
try {
fileUtils.safeDelete(tempFile);
fileService.safeDelete(tempFile);
} catch (IOException e) {
log.error("Failed to delete temporary export emote statistics file {}.", tempFile.getAbsoluteFile(), e);
}

View File

@@ -66,19 +66,19 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
// only show embed if static emote stats are available
if(!emoteStatsModel.getStaticEmotes().isEmpty()) {
log.trace("External emote stats has {} static emotes since {}.", emoteStatsModel.getStaticEmotes().size(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// only show embed if animated emote stats are available
if(!emoteStatsModel.getAnimatedEmotes().isEmpty()) {
log.trace("External emote stats has {} animated emotes since {}.", emoteStatsModel.getAnimatedEmotes(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, emoteStatsModel, commandContext.getChannel()));
}
// show an embed if no emote stats are available indicating so
if(!emoteStatsModel.areStatsAvailable()) {
log.info("No external emote stats available for guild {} since {}.", commandContext.getGuild().getIdLong(), statsSince);
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
}
return FutureUtils.toSingleFutureGeneric(messagePromises)

View File

@@ -48,7 +48,7 @@ public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
if(!trackedEmote.getExternal()) {
throw new AbstractoTemplatedException("Emote is not external", "showExternalTrackedEmote_emote_is_not_external");
}
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, trackedEmote, commandContext.getChannel()))
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, trackedEmote, commandContext.getChannel()))
.thenApply(unused -> CommandResult.fromIgnored());
}

View File

@@ -63,25 +63,25 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
// only show the embed, if there are static tracked emotes
if(!trackedEmoteOverview.getStaticEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
// only show the embed if there are animated tracked emotes
if(!trackedEmoteOverview.getAnimatedEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
// only show the embed, if there are deleted static emotes
if(!trackedEmoteOverview.getDeletedStaticEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
// only show the embed, if there are deleted animated emotes
if(!trackedEmoteOverview.getDeletedAnimatedEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, commandContext.getGuild().getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
@@ -92,19 +92,19 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
// only show the embed if there are external static emotes
if(!trackedEmoteOverview.getExternalStaticEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
// only show the embed if there are external animated emotes
if(!trackedEmoteOverview.getExternalAnimatedEmotes().isEmpty()) {
noTrackedEmotesAvailable = false;
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
}
}
// if there are no tracked emotes available, show an embed indicating so
if(noTrackedEmotesAvailable) {
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
messagePromises.addAll(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_NO_STATS_AVAILABLE, new Object(), commandContext.getChannel()));
}
return FutureUtils.toSingleFutureGeneric(messagePromises)
.thenApply(unused -> CommandResult.fromIgnored());

View File

@@ -39,7 +39,7 @@ public class SyncTrackedEmotes extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
TrackedEmoteSynchronizationResult syncResult = trackedEmoteService.synchronizeTrackedEmotes(commandContext.getGuild());
// show a result of how many emotes were deleted/added
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, syncResult, commandContext.getChannel()))
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, syncResult, commandContext.getChannel()))
.thenApply(unused -> CommandResult.fromIgnored());
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.statistic.emotes.command.parameter.handler;
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
import dev.sheldan.abstracto.core.command.handler.CommandParameterHandler;
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
@@ -47,12 +48,12 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
* does not need to actually exist.
*/
@Override
public Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context) {
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Class clazz, Message context) {
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, Emote.class, context);
if(emote != null) {
return trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild());
} else {
long trackedEmoteId = Long.parseLong(input);
long trackedEmoteId = Long.parseLong((String) input.getValue());
return trackedEmoteService.getFakeTrackedEmote(trackedEmoteId, context.getGuild());
}
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.statistic.emotes.command.parameter.handler;
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
import dev.sheldan.abstracto.core.command.handler.CommandParameterHandler;
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
@@ -50,14 +51,14 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
* used directly. In every successful case, it will contain a faked {@link TrackedEmote}.
*/
@Override
public Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context) {
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Class clazz, Message context) {
TrackEmoteParameter parameter = TrackEmoteParameter.builder().build();
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, Emote.class, context);
if(emote != null) {
parameter.setEmote(emote);
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild()));
} else {
long trackedEmoteId = Long.parseLong(input);
long trackedEmoteId = Long.parseLong((String) input.getValue());
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(trackedEmoteId, context.getGuild()));
}
return parameter;

View File

@@ -55,7 +55,7 @@ public class DeletedEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getDeletedEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -68,7 +68,7 @@ public class DeletedEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getDeletedEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -79,7 +79,7 @@ public class DeletedEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(false);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getDeletedEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -92,7 +92,7 @@ public class DeletedEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getDeletedEmoteStatsForServerSince(eq(server), any(Instant.class))).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_DELETED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}

View File

@@ -55,7 +55,7 @@ public class EmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getActiveEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -68,7 +68,7 @@ public class EmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getActiveEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -79,7 +79,7 @@ public class EmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(false);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getActiveEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -92,7 +92,7 @@ public class EmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getActiveEmoteStatsForServerSince(eq(server), any(Instant.class))).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}

View File

@@ -3,19 +3,19 @@ package dev.sheldan.abstracto.statistic.emotes.command;
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.exception.UploadFileTooLargeException;
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.core.utils.FileService;
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
import dev.sheldan.abstracto.statistic.emotes.exception.DownloadEmoteStatsFileTooBigException;
import dev.sheldan.abstracto.statistic.emotes.model.DownloadEmoteStatsModel;
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +55,7 @@ public class ExportEmoteStatsTest {
private UsedEmoteManagementService usedEmoteManagementService;
@Mock
private FileUtils fileUtils;
private FileService fileService;
@Captor
private ArgumentCaptor<DownloadEmoteStatsModel> modelArgumentCaptor;
@@ -74,16 +74,16 @@ public class ExportEmoteStatsTest {
when(commandContext.getGuild().getMaxFileSize()).thenReturn(4L);
mockServerAndFileRendering(commandContext);
File file = Mockito.mock(File.class);
when(fileUtils.createTempFile(FILE_NAME)).thenReturn(file);
when(fileService.createTempFile(FILE_NAME)).thenReturn(file);
when(file.length()).thenReturn(3L);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
when(templateService.renderEmbedTemplate(eq(DOWNLOAD_EMOTE_STATS_RESPONSE_TEMPLATE_KEY), any())).thenReturn(messageToSend);
when(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
verify(fileUtils, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(fileService, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(messageToSend, times(1)).setFileToSend(file);
verify(fileUtils, times(1)).safeDelete(file);
verify(fileService, times(1)).safeDelete(file);
verifyModel();
}
@@ -99,16 +99,16 @@ 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);
File file = Mockito.mock(File.class);
when(fileUtils.createTempFile(FILE_NAME)).thenReturn(file);
when(fileService.createTempFile(FILE_NAME)).thenReturn(file);
when(file.length()).thenReturn(3L);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
when(templateService.renderEmbedTemplate(eq(DOWNLOAD_EMOTE_STATS_RESPONSE_TEMPLATE_KEY), any())).thenReturn(messageToSend);
when(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
verify(fileUtils, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(fileService, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(messageToSend, times(1)).setFileToSend(file);
verify(fileUtils, times(1)).safeDelete(file);
verify(fileService, times(1)).safeDelete(file);
verifyModel();
}
@@ -122,7 +122,7 @@ public class ExportEmoteStatsTest {
when(usedEmoteManagementService.loadEmoteUsagesForServerSince(server, Instant.EPOCH)).thenReturn(usedEmotes);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
verify(channelService, times(1)).sendEmbedTemplateInChannel(eq(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY), any(), eq(commandContext.getChannel()));
verify(channelService, times(1)).sendEmbedTemplateInTextChannelList(eq(DOWNLOAD_EMOTE_STATS_NO_STATS_AVAILABLE_RESPONSE_TEMPLATE_KEY), any(), eq(commandContext.getChannel()));
}
@Test(expected = AbstractoRunTimeException.class)
@@ -130,25 +130,25 @@ public class ExportEmoteStatsTest {
CommandContext commandContext = CommandTestUtilities.getNoParameters();
mockServerAndFileRendering(commandContext);
File file = Mockito.mock(File.class);
when(fileUtils.createTempFile(FILE_NAME)).thenReturn(file);
doThrow(new IOException()).when(fileUtils).writeContentToFile(file, FILE_CONTENT);
when(fileService.createTempFile(FILE_NAME)).thenReturn(file);
doThrow(new IOException()).when(fileService).writeContentToFile(file, FILE_CONTENT);
testUnit.executeAsync(commandContext);
}
@Test(expected = DownloadEmoteStatsFileTooBigException.class)
@Test(expected = UploadFileTooLargeException.class)
public void testExportAllEmoteStatsTooBig() throws IOException {
CommandContext commandContext = CommandTestUtilities.getNoParameters();
when(commandContext.getGuild().getMaxFileSize()).thenReturn(2L);
mockServerAndFileRendering(commandContext);
File file = Mockito.mock(File.class);
when(fileUtils.createTempFile(FILE_NAME)).thenReturn(file);
when(fileService.createTempFile(FILE_NAME)).thenReturn(file);
when(file.length()).thenReturn(3L);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
verify(fileUtils, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(fileService, times(1)).writeContentToFile(file, FILE_CONTENT);
verify(messageToSend, times(1)).setFileToSend(file);
verify(fileUtils, times(1)).safeDelete(file);
verify(fileService, times(1)).safeDelete(file);
verifyModel();
}

View File

@@ -55,7 +55,7 @@ public class ExternalEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getExternalEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -68,7 +68,7 @@ public class ExternalEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getExternalEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -79,7 +79,7 @@ public class ExternalEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(false);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getExternalEmoteStatsForServerSince(server, Instant.EPOCH)).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(eq(EmoteStats.EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}
@@ -92,7 +92,7 @@ public class ExternalEmoteStatsTest {
when(model.areStatsAvailable()).thenReturn(true);
when(serverManagementService.loadServer(noParameters.getGuild())).thenReturn(server);
when(usedEmoteService.getExternalEmoteStatsForServerSince(eq(server), any(Instant.class))).thenReturn(model);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_EXTERNAL_RESPONSE, model, noParameters.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CommandTestUtilities.checkSuccessfulCompletionAsync(testUnit.executeAsync(noParameters));
}

View File

@@ -46,7 +46,7 @@ public class ShowExternalTrackedEmoteTest {
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
when(trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId())).thenReturn(actualTrackedEmote);
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote));
when(channelService.sendEmbedTemplateInChannel(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, actualTrackedEmote, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(SHOW_EXTERNAL_TRACKED_EMOTE_RESPONSE_TEMPLATE_KEY, actualTrackedEmote, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CompletableFuture<CommandResult> resultFuture = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(resultFuture);
}

View File

@@ -51,7 +51,7 @@ public class ShowTrackedEmotesTest {
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
when(channelService.sendEmbedTemplateInChannel(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
@@ -64,7 +64,7 @@ public class ShowTrackedEmotesTest {
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
when(channelService.sendEmbedTemplateInChannel(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), true)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
@@ -78,7 +78,7 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
AvailableTrackedEmote staticEmote = Mockito.mock(AvailableTrackedEmote.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getStaticEmotes()).thenReturn(Arrays.asList(staticEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -94,7 +94,7 @@ public class ShowTrackedEmotesTest {
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
AvailableTrackedEmote animatedEmote = Mockito.mock(AvailableTrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getAnimatedEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -110,7 +110,7 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
TrackedEmote animatedEmote = Mockito.mock(TrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getDeletedStaticEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -126,7 +126,7 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(false);
TrackedEmote animatedEmote = Mockito.mock(TrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getDeletedAnimatedEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -143,7 +143,7 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
TrackedEmote animatedEmote = Mockito.mock(TrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getExternalStaticEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -159,7 +159,7 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
TrackedEmote animatedEmote = Mockito.mock(TrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getExternalAnimatedEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), false)).thenReturn(overview);
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
@@ -175,12 +175,12 @@ public class ShowTrackedEmotesTest {
TrackedEmoteOverview overview = Mockito.mock(TrackedEmoteOverview.class);
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
TrackedEmote animatedEmote = Mockito.mock(TrackedEmote.class);
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, overview, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(overview.getExternalAnimatedEmotes()).thenReturn(Arrays.asList(animatedEmote));
when(overview.getExternalStaticEmotes()).thenReturn(Arrays.asList(animatedEmote));
AvailableTrackedEmote trackedEmote = Mockito.mock(AvailableTrackedEmote.class);
@@ -198,25 +198,25 @@ public class ShowTrackedEmotesTest {
private void verifyNoMessage(CommandContext commandContext, boolean noStats, boolean staticEmote, boolean animatedEmote, boolean deletedStatic, boolean deletedAnimated, boolean externalStatic, boolean externalAnimated) {
if(noStats) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_NO_STATS_AVAILABLE), any(), eq(commandContext.getChannel()));
}
if(staticEmote) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
}
if(animatedEmote) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
}
if(deletedStatic) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_DELETED_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_DELETED_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
}
if(deletedAnimated) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_DELETED_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_DELETED_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
}
if(externalStatic) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE), any(), eq(commandContext.getChannel()));
}
if(externalAnimated) {
verify(channelService, times(0)).sendEmbedTemplateInChannel(eq(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
verify(channelService, times(0)).sendEmbedTemplateInTextChannelList(eq(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE), any(), eq(commandContext.getChannel()));
}
}

View File

@@ -37,7 +37,7 @@ public class SyncTrackedEmotesTest {
CommandContext commandContext = CommandTestUtilities.getNoParameters();
TrackedEmoteSynchronizationResult result = Mockito.mock(TrackedEmoteSynchronizationResult.class);
when(trackedEmoteService.synchronizeTrackedEmotes(commandContext.getGuild())).thenReturn(result);
when(channelService.sendEmbedTemplateInChannel(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, result, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
when(channelService.sendEmbedTemplateInTextChannelList(SYNC_TRACKED_EMOTES_RESULT_RESPONSE, result, commandContext.getChannel())).thenReturn(CommandTestUtilities.messageFutureList());
CompletableFuture<CommandResult> asyncResult = testUnit.executeAsync(commandContext);
CommandTestUtilities.checkSuccessfulCompletionAsync(asyncResult);
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.statistic.emotes.command.handler;
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
import dev.sheldan.abstracto.statistic.emotes.command.parameter.handler.TrackedEmoteParameterHandler;
@@ -58,9 +59,10 @@ public class TrackedEmoteParameterHandlerTest {
public void testHandleWithEmote() {
when(contextMessage.getGuild()).thenReturn(guild);
Emote emote = Mockito.mock(Emote.class);
when(emoteParameterHandler.handle(WRONG_FORMATTED_INPUT, iterators, Emote.class, contextMessage)).thenReturn(emote);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(WRONG_FORMATTED_INPUT).build();
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(emote);
when(trackedEmoteService.getFakeTrackedEmote(emote, guild)).thenReturn(trackedEmote);
TrackedEmote parsedEmote = (TrackedEmote) testUnit.handle(WRONG_FORMATTED_INPUT, iterators, TrackedEmote.class, contextMessage);
TrackedEmote parsedEmote = (TrackedEmote) testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
Assert.assertEquals(trackedEmote, parsedEmote);
}
@@ -68,16 +70,18 @@ public class TrackedEmoteParameterHandlerTest {
public void testHandleWithId() {
Long emoteId = 5L;
when(contextMessage.getGuild()).thenReturn(guild);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(emoteId.toString()).build();
when(trackedEmoteService.getFakeTrackedEmote(emoteId, guild)).thenReturn(trackedEmote);
when(emoteParameterHandler.handle(emoteId.toString(), iterators, Emote.class, contextMessage)).thenReturn(null);
TrackedEmote parsedEmote = (TrackedEmote) testUnit.handle(emoteId.toString(), iterators, TrackedEmote.class, contextMessage);
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(null);
TrackedEmote parsedEmote = (TrackedEmote) testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(Emote.class), eq(guild));
Assert.assertEquals(trackedEmote, parsedEmote);
}
@Test(expected = NumberFormatException.class)
public void testWithIllegalInput() {
when(emoteParameterHandler.handle(WRONG_FORMATTED_INPUT, iterators, Emote.class, contextMessage)).thenReturn(null);
testUnit.handle(WRONG_FORMATTED_INPUT, iterators, TrackedEmote.class, contextMessage);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(WRONG_FORMATTED_INPUT).build();
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(null);
testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
}
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.statistic.emotes.command.handler;
import dev.sheldan.abstracto.core.command.execution.UnparsedCommandParameterPiece;
import dev.sheldan.abstracto.core.command.handler.CommandParameterIterators;
import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler;
import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter;
@@ -61,9 +62,10 @@ public class TrackedEmoteParameterParameterHandlerTest {
public void testHandleWithEmote() {
when(contextMessage.getGuild()).thenReturn(guild);
Emote emote = Mockito.mock(Emote.class);
when(emoteParameterHandler.handle(WRONG_FORMATTED_INPUT, iterators, Emote.class, contextMessage)).thenReturn(emote);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(WRONG_FORMATTED_INPUT).build();
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(emote);
when(trackedEmoteService.getFakeTrackedEmote(emote, guild)).thenReturn(trackedEmote);
TrackEmoteParameter parsedEmote = (TrackEmoteParameter) testUnit.handle(WRONG_FORMATTED_INPUT, iterators, TrackedEmote.class, contextMessage);
TrackEmoteParameter parsedEmote = (TrackEmoteParameter) testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
Assert.assertEquals(trackedEmote, parsedEmote.getTrackedEmote());
Assert.assertEquals(emote, parsedEmote.getEmote());
}
@@ -72,17 +74,19 @@ public class TrackedEmoteParameterParameterHandlerTest {
public void testHandleWithId() {
Long emoteId = 5L;
when(contextMessage.getGuild()).thenReturn(guild);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(emoteId.toString()).build();
when(trackedEmoteService.getFakeTrackedEmote(emoteId, guild)).thenReturn(trackedEmote);
when(emoteParameterHandler.handle(emoteId.toString(), iterators, Emote.class, contextMessage)).thenReturn(null);
TrackEmoteParameter parsedEmote = (TrackEmoteParameter) testUnit.handle(emoteId.toString(), iterators, TrackedEmote.class, contextMessage);
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(null);
TrackEmoteParameter parsedEmote = (TrackEmoteParameter) testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
verify(trackedEmoteService, times(0)).getFakeTrackedEmote(any(Emote.class), eq(guild));
Assert.assertEquals(trackedEmote, parsedEmote.getTrackedEmote());
}
@Test(expected = NumberFormatException.class)
public void testWithIllegalInput() {
when(emoteParameterHandler.handle(WRONG_FORMATTED_INPUT, iterators, Emote.class, contextMessage)).thenReturn(null);
testUnit.handle(WRONG_FORMATTED_INPUT, iterators, TrackedEmote.class, contextMessage);
UnparsedCommandParameterPiece input = UnparsedCommandParameterPiece.builder().value(WRONG_FORMATTED_INPUT).build();
when(emoteParameterHandler.handle(input, iterators, Emote.class, contextMessage)).thenReturn(null);
testUnit.handle(input, iterators, TrackedEmote.class, contextMessage);
}
}

View File

@@ -1,28 +0,0 @@
package dev.sheldan.abstracto.statistic.emotes.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.statistic.emotes.model.exception.DownloadEmoteStatsFileTooBigModel;
import dev.sheldan.abstracto.templating.Templatable;
/**
* Exception in case the CSV file created by `exportEmoteStats` is larger than the file size limit of the guild it was requested in.
* TODO: split this up into multiple files (total max), in order to make this exception obsolete
*/
public class DownloadEmoteStatsFileTooBigException extends AbstractoRunTimeException implements Templatable {
private final DownloadEmoteStatsFileTooBigModel model;
public DownloadEmoteStatsFileTooBigException(Long fileSize, Long maxFileSize) {
this.model = DownloadEmoteStatsFileTooBigModel.builder().fileSize(fileSize).fileSizeLimit(maxFileSize).build();
}
@Override
public String getTemplateName() {
return "emote_stats_download_file_size_too_big";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.statistic.emotes.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.templating.Templatable;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception which is cased in a case the {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} could not be found.

View File

@@ -1,25 +0,0 @@
package dev.sheldan.abstracto.statistic.emotes.model.exception;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* Model used for {@link dev.sheldan.abstracto.statistic.emotes.exception.DownloadEmoteStatsFileTooBigException} which contains
* the file size of the file which was created and the max file size allowed on the server.
*/
@Getter
@Setter
@Builder
public class DownloadEmoteStatsFileTooBigModel implements Serializable {
/**
* File size in bytes of the file being created for emote stats
*/
private Long fileSize;
/**
* The file size limit of the server in bytes which was lower than the files size of the file
*/
private Long fileSizeLimit;
}