mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-17 12:34:46 +00:00
[AB-60] added java doc for statistic module, added feature mode limitations to emote listener, replaced redundant Embeddable with ServerSpecificId
This commit is contained in:
@@ -4,6 +4,9 @@ import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Help module for all statistics related commands, they have their own module if they have a significant emount of commands on their own.
|
||||
*/
|
||||
@Component
|
||||
public class StatisticModule implements ModuleInterface {
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command completely deletes one individual {@link TrackedEmote} and all of its usages from the database. This command cannot be undone.
|
||||
*/
|
||||
@Component
|
||||
public class DeleteTrackedEmote extends AbstractConditionableCommand {
|
||||
|
||||
@@ -32,6 +35,7 @@ public class DeleteTrackedEmote extends AbstractConditionableCommand {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
|
||||
// need to actually load the TrackedEmote
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId());
|
||||
trackedEmoteService.deleteTrackedEmote(trackedEmote);
|
||||
return CommandResult.fromSuccess();
|
||||
@@ -44,7 +48,7 @@ public class DeleteTrackedEmote extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("deleteTrackedEmote")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -10,7 +10,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.UsedEmoteService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -24,6 +24,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command will show the emote statistics for all deleted emotes in the current server. There is an optional
|
||||
* {@link Duration} parameter, which will define the amount of time to retrieve the stats for. If not provided, all stats will be shown.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeletedEmoteStats extends AbstractConditionableCommand {
|
||||
@@ -41,21 +45,26 @@ public class DeletedEmoteStats extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
// default is 1.1.1970
|
||||
Instant statsSince = Instant.EPOCH;
|
||||
if(!parameters.isEmpty()) {
|
||||
// if a duration parameter is available, subtract the current time of this to get the true Instant
|
||||
Duration duration = (Duration) parameters.get(0);
|
||||
statsSince = Instant.now().minus(duration);
|
||||
}
|
||||
EmoteStatsModel emoteStatsModel = usedEmoteService.getDeletedEmoteStatsForServerSince(commandContext.getUserInitiatedContext().getServer(), statsSince);
|
||||
List<CompletableFuture<Message>> messagePromises = new ArrayList<>();
|
||||
// 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()));
|
||||
}
|
||||
// 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()));
|
||||
}
|
||||
// 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()));
|
||||
@@ -72,7 +81,7 @@ public class DeletedEmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("deletedEmoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -8,7 +8,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command disables the tracking for either one {@link TrackedEmote} or for all of them, if no emote is given as a parameter
|
||||
*/
|
||||
@Component
|
||||
public class DisableEmoteTracking extends AbstractConditionableCommand {
|
||||
|
||||
@@ -33,6 +36,7 @@ public class DisableEmoteTracking extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
if(!parameters.isEmpty()) {
|
||||
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
|
||||
// need to reload the tracked emote
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId());
|
||||
trackedEmoteManagementService.disableTrackedEmote(trackedEmote);
|
||||
} else {
|
||||
@@ -48,7 +52,7 @@ public class DisableEmoteTracking extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("disableEmoteTracking")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -8,10 +8,9 @@ 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.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.UsedEmoteService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -25,6 +24,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command displays the emote stats for the current {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} within the
|
||||
* {@link net.dv8tion.jda.api.entities.Guild} the command has been executed in
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EmoteStats extends AbstractConditionableCommand {
|
||||
@@ -35,9 +38,6 @@ public class EmoteStats extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
public static final String EMOTE_STATS_STATIC_RESPONSE = "emoteStats_static_response";
|
||||
public static final String EMOTE_STATS_ANIMATED_RESPONSE = "emoteStats_animated_response";
|
||||
public static final String EMOTE_STATS_NO_STATS_AVAILABLE = "emoteStats_no_stats_available";
|
||||
@@ -46,21 +46,26 @@ public class EmoteStats extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
// default is 1.1.1970
|
||||
Instant statsSince = Instant.EPOCH;
|
||||
if(!parameters.isEmpty()) {
|
||||
// subtract the given Duration from the current point in time, if there is any
|
||||
Duration duration = (Duration) parameters.get(0);
|
||||
statsSince = Instant.now().minus(duration);
|
||||
}
|
||||
EmoteStatsModel emoteStatsModel = usedEmoteService.getActiveEmoteStatsForServerSince(commandContext.getUserInitiatedContext().getServer(), statsSince);
|
||||
List<CompletableFuture<Message>> messagePromises = new ArrayList<>();
|
||||
// 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()));
|
||||
}
|
||||
// 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()));
|
||||
}
|
||||
// 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()));
|
||||
@@ -77,7 +82,7 @@ public class EmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("emoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -14,7 +14,7 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FileUtils;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
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;
|
||||
@@ -33,6 +33,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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}.
|
||||
* This will create a temporary file on the server, which will be deleted after it has been send.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
@@ -61,12 +68,15 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Instant statsSince = Instant.EPOCH;
|
||||
// default is 1.1.1970
|
||||
if(!parameters.isEmpty()) {
|
||||
// if a duration is given, subtract this duration from the current point in time
|
||||
Duration duration = (Duration) parameters.get(0);
|
||||
statsSince = Instant.now().minus(duration);
|
||||
}
|
||||
AServer actualServer = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
|
||||
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()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
@@ -88,6 +98,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
try {
|
||||
fileUtils.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);
|
||||
}
|
||||
@@ -113,7 +124,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("exportEmoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -9,11 +9,10 @@ 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.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.UsedEmoteService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -28,6 +27,10 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command will show the emote statistics for all emotes which are tracked in the current server, but are not from that server.
|
||||
* There is an optional {@link Duration} parameter, which will define the amount of time to retrieve the stats for. If not provided, all stats will be shown.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ExternalEmoteStats extends AbstractConditionableCommand {
|
||||
@@ -38,9 +41,6 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
public static final String EMOTE_STATS_STATIC_EXTERNAL_RESPONSE = "externalEmoteStats_static_response";
|
||||
public static final String EMOTE_STATS_ANIMATED_EXTERNAL_RESPONSE = "externalEmoteStats_animated_response";
|
||||
|
||||
@@ -48,22 +48,29 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
// default is 1.1.1970
|
||||
Instant statsSince = Instant.EPOCH;
|
||||
if(!parameters.isEmpty()) {
|
||||
// subtract the given Duration parameter from the current point in time
|
||||
Duration duration = (Duration) parameters.get(0);
|
||||
statsSince = Instant.now().minus(duration);
|
||||
}
|
||||
EmoteStatsModel emoteStatsModel = usedEmoteService.getExternalEmoteStatsForServerSince(commandContext.getUserInitiatedContext().getServer(), statsSince);
|
||||
List<CompletableFuture<Message>> messagePromises = new ArrayList<>();
|
||||
|
||||
// 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()));
|
||||
}
|
||||
|
||||
// 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()));
|
||||
}
|
||||
|
||||
// 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()));
|
||||
@@ -80,7 +87,7 @@ public class ExternalEmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("externalEmoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -8,7 +8,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.UsedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
@@ -20,6 +20,10 @@ import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command will delete the instances of {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote} of a given {@link TrackedEmote}
|
||||
* for the desired {@link Duration}, or all of them. This command cannot be undone.
|
||||
*/
|
||||
@Component
|
||||
public class PurgeEmoteStats extends AbstractConditionableCommand {
|
||||
|
||||
@@ -35,8 +39,10 @@ public class PurgeEmoteStats extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId());
|
||||
// default 1.1.1970
|
||||
Instant since = Instant.EPOCH;
|
||||
if(parameters.size() > 1) {
|
||||
// if a Duration is given, subtract it from the current point in time
|
||||
Duration parameter = (Duration) parameters.get(1);
|
||||
since = Instant.now().minus(parameter);
|
||||
}
|
||||
@@ -52,7 +58,7 @@ public class PurgeEmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("purgeEmoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -8,7 +8,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -16,6 +16,10 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command removes all {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote} instances
|
||||
* and all {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} in a guild. This command cannot be undone.
|
||||
*/
|
||||
@Component
|
||||
public class ResetEmoteStats extends AbstractConditionableCommand {
|
||||
|
||||
@@ -34,7 +38,7 @@ public class ResetEmoteStats extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("resetEmoteStats")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -12,8 +12,8 @@ import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,6 +24,10 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command is used to show the image and provide the link of an external {@link TrackedEmote}. It is only available, if the
|
||||
* EmoteTrackingMode.EXTERNAL_EMOTES is active.
|
||||
*/
|
||||
@Component
|
||||
public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
|
||||
|
||||
@@ -39,7 +43,9 @@ public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
TrackedEmote fakeTrackedEmote = (TrackedEmote) parameters.get(0);
|
||||
// load the actual TrackedEmote instance
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId());
|
||||
// the command only works for external emotes
|
||||
if(!trackedEmote.getExternal()) {
|
||||
throw new AbstractoTemplatedException("Emote is not external", "showExternalTrackedEmote_emote_is_not_external");
|
||||
}
|
||||
@@ -54,7 +60,7 @@ public class ShowExternalTrackedEmote extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("showExternalTrackedEmote")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -11,8 +11,8 @@ import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteOverview;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -23,6 +23,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command gives an overview over all {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} in a guild.
|
||||
* It will not show external emotes, if the feature mode EmoteTrackingMode.EXTERNAL_EMOTES is disabled. There is a parameter to also show
|
||||
* emotes for which the tracking has been disabled
|
||||
*/
|
||||
@Component
|
||||
public class ShowTrackedEmotes extends AbstractConditionableCommand {
|
||||
|
||||
@@ -47,43 +52,59 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
|
||||
// per default, do not show TrackedEmote for which tracking has been disabled
|
||||
Boolean showTrackingDisabled = false;
|
||||
if(!commandContext.getParameters().getParameters().isEmpty()) {
|
||||
showTrackingDisabled = (Boolean) commandContext.getParameters().getParameters().get(0);
|
||||
}
|
||||
|
||||
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, commandContext.getGuild().getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
|
||||
TrackedEmoteOverview trackedEmoteOverview = trackedEmoteService.loadTrackedEmoteOverview(commandContext.getGuild(), showTrackingDisabled);
|
||||
boolean noStatsAvailable = true;
|
||||
boolean noTrackedEmotesAvailable = true;
|
||||
List<CompletableFuture<Message>> messagePromises = new ArrayList<>();
|
||||
// only show the embed, if there are static tracked emotes
|
||||
if(!trackedEmoteOverview.getStaticEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed if there are animated tracked emotes
|
||||
if(!trackedEmoteOverview.getAnimatedEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed, if there are deleted static emotes
|
||||
if(!trackedEmoteOverview.getDeletedStaticEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed, if there are deleted animated emotes
|
||||
if(!trackedEmoteOverview.getDeletedAnimatedEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_DELETED_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, commandContext.getGuild().getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
|
||||
// only show external emotes if external emotes are enabled
|
||||
if(externalTrackingEnabled) {
|
||||
|
||||
// only show the embed if there are external static emotes
|
||||
if(!trackedEmoteOverview.getExternalStaticEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_STATIC_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
|
||||
// only show the embed if there are external animated emotes
|
||||
if(!trackedEmoteOverview.getExternalAnimatedEmotes().isEmpty()) {
|
||||
noStatsAvailable = false;
|
||||
noTrackedEmotesAvailable = false;
|
||||
messagePromises.addAll(channelService.sendEmbedTemplateInChannel(EMOTE_STATS_EXTERNAL_ANIMATED_RESPONSE, trackedEmoteOverview, commandContext.getChannel()));
|
||||
}
|
||||
}
|
||||
if(noStatsAvailable) {
|
||||
|
||||
// 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()));
|
||||
}
|
||||
return FutureUtils.toSingleFutureGeneric(messagePromises)
|
||||
@@ -97,7 +118,7 @@ public class ShowTrackedEmotes extends AbstractConditionableCommand {
|
||||
parameters.add(Parameter.builder().name("showAll").templated(true).optional(true).type(Boolean.class).build());
|
||||
return CommandConfiguration.builder()
|
||||
.name("showTrackedEmotes")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -10,7 +10,7 @@ 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.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteSynchronizationResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,6 +20,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command can be used to synchronize the state of {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote}
|
||||
* in the database, with the state of {@link net.dv8tion.jda.api.entities.Emote} in the {@link net.dv8tion.jda.api.entities.Guild}.
|
||||
* It will mark emotes not in the guild anymore and add emotes which are not yet tracked.
|
||||
*/
|
||||
@Component
|
||||
public class SyncTrackedEmotes extends AbstractConditionableCommand {
|
||||
|
||||
@@ -33,6 +38,7 @@ public class SyncTrackedEmotes extends AbstractConditionableCommand {
|
||||
@Override
|
||||
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()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
@@ -43,7 +49,7 @@ public class SyncTrackedEmotes extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("syncTrackedEmotes")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -11,9 +11,9 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingModule;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
@@ -23,6 +23,10 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command can be used to track one individual {@link TrackedEmote} newly, or set the emote to be tracked again.
|
||||
* This can either be done via providing the {@link net.dv8tion.jda.api.entities.Emote} or via ID.
|
||||
*/
|
||||
@Component
|
||||
public class TrackEmote extends AbstractConditionableCommand {
|
||||
|
||||
@@ -42,18 +46,22 @@ public class TrackEmote extends AbstractConditionableCommand {
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
TrackEmoteParameter emoteToTrack = (TrackEmoteParameter) commandContext.getParameters().getParameters().get(0);
|
||||
Long emoteId = emoteToTrack.getTrackedEmote().getTrackedEmoteId().getEmoteId();
|
||||
Long emoteId = emoteToTrack.getTrackedEmote().getTrackedEmoteId().getId();
|
||||
long serverId = commandContext.getGuild().getIdLong();
|
||||
// if its already a tracked emote, just set the tracking_enabled flag to true
|
||||
if(trackedEmoteManagementService.trackedEmoteExists(emoteId, serverId)) {
|
||||
TrackedEmote trackedemote = trackedEmoteManagementService.loadByEmoteId(emoteId, serverId);
|
||||
trackedEmoteManagementService.enableTrackedEmote(trackedemote);
|
||||
} else if(emoteToTrack.getEmote() != null) {
|
||||
// if its a new emote, lets see if its external
|
||||
boolean external = !emoteService.emoteIsFromGuild(emoteToTrack.getEmote(), commandContext.getGuild());
|
||||
if(external) {
|
||||
// this throws an exception if the feature mode is not enabled
|
||||
featureModeService.validateActiveFeatureMode(serverId, StatisticFeatures.EMOTE_TRACKING, EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
}
|
||||
trackedEmoteService.createFakeTrackedEmote(emoteToTrack.getEmote(), commandContext.getGuild(), external);
|
||||
trackedEmoteService.createTrackedEmote(emoteToTrack.getEmote(), commandContext.getGuild(), external);
|
||||
} else {
|
||||
// in case the ID was not an existing TrackedEmote, and no Emote was given, we need to fail
|
||||
throw new IncorrectParameterException(this, getConfiguration().getParameters().get(0).getName());
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
@@ -66,7 +74,7 @@ public class TrackEmote extends AbstractConditionableCommand {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("trackEmote")
|
||||
.module(StatisticModule.STATISTIC)
|
||||
.module(EmoteTrackingModule.EMOTE_TRACKING)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -6,10 +6,21 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
/**
|
||||
* Container class for containing both an {@link Emote} and a {@link TrackedEmote} for the purpose of a {@link dev.sheldan.abstracto.core.command.config.Parameter}.
|
||||
* This is used in {@link dev.sheldan.abstracto.statistic.emotes.command.TrackEmote} and is used as a convenience parameter, in which there
|
||||
* might both a {@link Emote} and a {@link TrackedEmote} as parameter
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class TrackEmoteParameter {
|
||||
/**
|
||||
* If an {@link Emote} has been used as parameter, this will have the appropriate value
|
||||
*/
|
||||
private Emote emote;
|
||||
/**
|
||||
* If a {@link Long} or {@link Emote} has been supplied as the parameter, this will contain a faked instance of the respective values
|
||||
*/
|
||||
private TrackedEmote trackedEmote;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* {@link CommandParameterHandler} for the {@link TrackedEmote} class. This parameter handler will only create
|
||||
* fake {@link TrackedEmote} and it has a priority a bit higher than medium.
|
||||
*/
|
||||
@Component
|
||||
public class TrackedEmoteParameterHandler implements CommandParameterHandler {
|
||||
|
||||
@@ -19,11 +23,29 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
|
||||
@Autowired
|
||||
private TrackedEmoteService trackedEmoteService;
|
||||
|
||||
/**
|
||||
* This {@link CommandParameterHandler} only handles {@link TrackedEmote}
|
||||
* @param clazz The desired {@link Class} of a parameter
|
||||
* @return Whether or not the given {@link Class} will be handled by this {@link CommandParameterHandler}
|
||||
*/
|
||||
@Override
|
||||
public boolean handles(Class clazz) {
|
||||
return clazz.equals(TrackedEmote.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will parse the input for potential {@link TrackedEmote} and return a fake instance of such.
|
||||
* At first it will see if there are any {@link Emote} directly in the message. If there are none at the current position
|
||||
* it will try to parse the parameter to a {@link Long}. It is *not* guaranteed that a {@link TrackedEmote} with this ID
|
||||
* really exists for this server. So, any commands using this are required to do checks on their own.
|
||||
* @param input The {@link String} input at the current position
|
||||
* @param iterators The {@link CommandParameterIterators} containing all available iterators to directly retrieve JDA related
|
||||
* entities from
|
||||
* @param clazz The {@link Class} which this type should handle
|
||||
* @param context The {@link Message} which caused the command to be executed
|
||||
* @return A faked {@link TrackedEmote} based on the given input or from {@link CommandParameterIterators} directly. This {@link TrackedEmote}
|
||||
* does not need to actually exist.
|
||||
*/
|
||||
@Override
|
||||
public Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context) {
|
||||
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, Emote.class, context);
|
||||
|
||||
@@ -4,12 +4,20 @@ 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;
|
||||
import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* {@link CommandParameterHandler} for the {@link TrackEmoteParameter} class. It will call the
|
||||
* {@link EmoteParameterHandler} and use the returned {@link Emote} if one is available. Otherwise it will only use the
|
||||
* {@link Long} which was passed. This handler will create a fake instance for the {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote}
|
||||
* and only make the {@link Emote} available in the result, if it was passed as such. This handler has a slightly higher priority
|
||||
* than medium.
|
||||
*/
|
||||
@Component
|
||||
public class TrackedEmoteParameterParameterHandler implements CommandParameterHandler {
|
||||
|
||||
@@ -19,11 +27,28 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
|
||||
@Autowired
|
||||
private TrackedEmoteService trackedEmoteService;
|
||||
|
||||
/**
|
||||
* This {@link CommandParameterHandler} only handles {@link TrackEmoteParameter}
|
||||
* @param clazz The desired {@link Class} of a parameter
|
||||
* @return Whether or not the given {@link Class} will be handled by this {@link CommandParameterHandler}
|
||||
*/
|
||||
@Override
|
||||
public boolean handles(Class clazz) {
|
||||
return clazz.equals(TrackEmoteParameter.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tries to parse the input and extract an {@link Emote} or just an {@link Long}. It uses a {@link EmoteParameterHandler} at first,
|
||||
* and if nothing is found tries to parse the {@link Long} directly from the input. In case an {@link Emote} was used, this will populate the
|
||||
* respective member variable in {@link TrackEmoteParameter}.
|
||||
* @param input The {@link String} input at the current position
|
||||
* @param iterators The {@link CommandParameterIterators} containing all available iterators to directly retrieve JDA related
|
||||
* entities from
|
||||
* @param clazz The {@link Class} which this type should handle
|
||||
* @param context The {@link Message} which caused the command to be executed
|
||||
* @return An instance of {@link TrackEmoteParameter} which contains the available instances. This is an {@link Emote} in case it was
|
||||
* 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) {
|
||||
TrackEmoteParameter parameter = TrackEmoteParameter.builder().build();
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticModule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Separate module just for all commands related to emote tracking.
|
||||
*/
|
||||
@Component
|
||||
public class EmoteTrackingModule implements ModuleInterface {
|
||||
public static final String EMOTE_TRACKING = "emoteTracking";
|
||||
|
||||
@Override
|
||||
public ModuleInfo getInfo() {
|
||||
return ModuleInfo.builder().name(EMOTE_TRACKING).description("Module containing commands related to emote tracking.").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentModule() {
|
||||
return StatisticModule.STATISTIC;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,11 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Component to convert from a {@link EmoteStatsResult} to a proper instance of {@link EmoteStatsModel}.
|
||||
* This for example loads the relevant {@link Emote} to be used within the model and also splits it up
|
||||
* into static and animated emotes
|
||||
*/
|
||||
@Component
|
||||
public class EmoteStatsConverter {
|
||||
|
||||
@@ -24,15 +29,18 @@ public class EmoteStatsConverter {
|
||||
|
||||
public EmoteStatsModel fromEmoteStatsResults(List<EmoteStatsResult> resultList) {
|
||||
if(resultList.isEmpty()) {
|
||||
// no stats are available, do nothing
|
||||
return EmoteStatsModel.builder().build();
|
||||
}
|
||||
// it is assumed all emotes are tracked in the same server
|
||||
Guild relevantGuild = botService.getGuildById(resultList.get(0).getServerId());
|
||||
EmoteStatsModel resultingModel = EmoteStatsModel.builder().build();
|
||||
resultList.forEach(emoteStatsResult -> {
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByEmoteId(emoteStatsResult.getEmoteId(), emoteStatsResult.getServerId());
|
||||
Emote loadedEmote = null;
|
||||
// if the emote should still exist, we try to load it
|
||||
if(!trackedEmote.getExternal() && !trackedEmote.getDeleted()) {
|
||||
loadedEmote = relevantGuild.getEmoteById(trackedEmote.getTrackedEmoteId().getEmoteId());
|
||||
loadedEmote = relevantGuild.getEmoteById(trackedEmote.getTrackedEmoteId().getId());
|
||||
}
|
||||
EmoteStatsResultDisplay display = EmoteStatsResultDisplay
|
||||
.builder()
|
||||
|
||||
@@ -18,6 +18,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Job responsible for persisting the emote usages found in {@link TrackedEmoteRuntimeService} to the database.
|
||||
* This will create new instances, if there are non before, and increment past instances. This job runs for all servers globally.
|
||||
*/
|
||||
@Slf4j
|
||||
@DisallowConcurrentExecution
|
||||
@Component
|
||||
@@ -33,24 +37,30 @@ public class EmotePersistingJob extends QuartzJobBean {
|
||||
@Override
|
||||
@Transactional
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
// acquire the lock, because we are modifying
|
||||
trackedEmoteRuntimeService.takeLock();
|
||||
Long pastMinute = getPastMinute();
|
||||
Map<Long, Map<Long, List<PersistingEmote>>> runtimeConfig = trackedEmoteRuntimeService.getRuntimeConfig();
|
||||
try {
|
||||
Map<Long, Map<Long, List<PersistingEmote>>> runtimeConfig = trackedEmoteRuntimeService.getRuntimeConfig();
|
||||
log.info("Running statistic persisting job.");
|
||||
Long pastMinute = getPastMinute();
|
||||
// only take the emotes from the last minute, if there are any
|
||||
if(runtimeConfig.containsKey(pastMinute)) {
|
||||
Map<Long, List<PersistingEmote>> foundStatistics = runtimeConfig.get(pastMinute);
|
||||
log.info("Found emote statistics from {} servers to persist.", foundStatistics.size());
|
||||
trackedEmoteService.storeEmoteStatistics(foundStatistics);
|
||||
runtimeConfig.remove(pastMinute);
|
||||
// remove it, because we processed it
|
||||
// check for earlier entries which were missed
|
||||
checkForPastEmoteStats(pastMinute, runtimeConfig);
|
||||
}
|
||||
} finally {
|
||||
runtimeConfig.remove(pastMinute);
|
||||
// release the lock, so other listeners can add onto it again
|
||||
trackedEmoteRuntimeService.releaseLock();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForPastEmoteStats(Long minuteToCheck, Map<Long, Map<Long, List<PersistingEmote>>> runtimeConfig) {
|
||||
// if there are any keys which have a lower minute, we need to process them, because they most likely have not been processed yet
|
||||
List<Long> missedMinutes = runtimeConfig.keySet().stream().filter(aLong -> aLong < minuteToCheck).collect(Collectors.toList());
|
||||
missedMinutes.forEach(pastMinute -> {
|
||||
log.info("Persisting emotes for a minute in the past, it should have been previously, but was not. Minute {}.", pastMinute);
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.listener.EmoteCreatedListener;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This listener listens for created {@link Emote} in a {@link net.dv8tion.jda.api.entities.Guild} and creates appropriate
|
||||
* {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote}, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
|
||||
* feature mode as well.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CreateTrackedEmoteListener implements EmoteCreatedListener {
|
||||
@@ -33,4 +43,9 @@ public class CreateTrackedEmoteListener implements EmoteCreatedListener {
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.MEDIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getFeatureModeLimitations() {
|
||||
return Arrays.asList(EmoteTrackingMode.AUTO_TRACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.listener.EmoteDeletedListener;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This listener listens for deleted {@link Emote} in a {@link net.dv8tion.jda.api.entities.Guild} and markes respective
|
||||
* {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} as deleted, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
|
||||
* feature mode as well.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeleteTrackedEmoteListener implements EmoteDeletedListener {
|
||||
@@ -32,4 +42,9 @@ public class DeleteTrackedEmoteListener implements EmoteDeletedListener {
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.MEDIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getFeatureModeLimitations() {
|
||||
return Arrays.asList(EmoteTrackingMode.AUTO_TRACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This listener listens to every received message, if the EMOTE_TRACKING feature is enabled, and stores *all* used emotes in
|
||||
* the runtime storage for emote tracking.
|
||||
*/
|
||||
@Component
|
||||
public class EmoteTrackingListener implements MessageReceivedListener {
|
||||
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.listener.EmoteUpdatedListener;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This listener listens for emote name changes and appropriately updates the name of the {@link TrackedEmote} in the database,
|
||||
* if the emote is tracked. This is only executed if the EMOTE_TRACKING feature is enabled,and if the AUTO_TRACK feature mode is enabled.
|
||||
*/
|
||||
@Component
|
||||
public class UpdateTrackedEmoteListener implements EmoteUpdatedListener {
|
||||
|
||||
@@ -31,4 +40,9 @@ public class UpdateTrackedEmoteListener implements EmoteUpdatedListener {
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.MEDIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getFeatureModeLimitations() {
|
||||
return Arrays.asList(EmoteTrackingMode.AUTO_TRACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.QueryHints;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -9,14 +9,35 @@ import org.springframework.stereotype.Repository;
|
||||
import javax.persistence.QueryHint;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Repository responsible for database operations on {@link TrackedEmote}
|
||||
*/
|
||||
@Repository
|
||||
public interface TrackedEmoteRepository extends JpaRepository<TrackedEmote, TrackedEmoteServer> {
|
||||
public interface TrackedEmoteRepository extends JpaRepository<TrackedEmote, ServerSpecificId> {
|
||||
/**
|
||||
* Retrieves all {@link TrackedEmote} from a {@link dev.sheldan.abstracto.core.models.database.AServer} via the ID
|
||||
* which are not deleted and not external
|
||||
* @param serverId The ID of the {@link dev.sheldan.abstracto.core.models.database.AServer} to retrieve the {@link TrackedEmote} for
|
||||
* @return A list of {@link TrackedEmote} from the {@link dev.sheldan.abstracto.core.models.database.AServer} identified by ID, which are not deleted or external
|
||||
*/
|
||||
@QueryHints(@QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true"))
|
||||
List<TrackedEmote> findByTrackedEmoteId_ServerIdAndDeletedFalseAndExternalFalse(Long serverId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link TrackedEmote} from a {@link dev.sheldan.abstracto.core.models.database.AServer} via the ID
|
||||
* which have their tracking enabled
|
||||
* @param serverId The ID of the {@link dev.sheldan.abstracto.core.models.database.AServer} to retrieve the {@link TrackedEmote} for
|
||||
* @return A list of {@link TrackedEmote} from the {@link dev.sheldan.abstracto.core.models.database.AServer} identified by ID, which have their tracking enabled
|
||||
*/
|
||||
@QueryHints(@QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true"))
|
||||
List<TrackedEmote> findByTrackedEmoteId_ServerIdAndTrackingEnabledTrue(Long serverId);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all {@link TrackedEmote} from a {@link dev.sheldan.abstracto.core.models.database.AServer} via the ID
|
||||
* @param serverId The ID of the {@link dev.sheldan.abstracto.core.models.database.AServer} to retrieve the {@link TrackedEmote} for
|
||||
* @return A list of {@link TrackedEmote} from the {@link dev.sheldan.abstracto.core.models.database.AServer} identified by ID
|
||||
*/
|
||||
@QueryHints(@QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true"))
|
||||
List<TrackedEmote> findByTrackedEmoteId_ServerId(Long serverId);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,20 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Repository used to query and created {@link UsedEmote}. This also includes query for the emote statistics.
|
||||
*/
|
||||
@Repository
|
||||
public interface UsedEmoteRepository extends JpaRepository<UsedEmote, UsedEmoteDay> {
|
||||
|
||||
/**
|
||||
* Selects the {@link UsedEmote} for one particular {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote}
|
||||
* for the current date.
|
||||
* @param emoteId The ID of the {@link net.dv8tion.jda.api.entities.Emote} which is being tracked
|
||||
* @param server_id The ID of the {@link net.dv8tion.jda.api.entities.Guild} which is the server where the {@link net.dv8tion.jda.api.entities.Emote}
|
||||
* is being tracked
|
||||
* @return An {@link Optional} containing a possible {@link UsedEmote}, if it exists for the criteria, an empty Optional otherwise.
|
||||
*/
|
||||
@Query(value="select * from used_emote " +
|
||||
"where emote_id = :emote_id and server_id = :server_id " +
|
||||
"and use_date = date_trunc('day', now())", nativeQuery = true)
|
||||
|
||||
@@ -7,22 +7,50 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Component actually containing the data structure containing the runtime storage for emote statistics.
|
||||
*/
|
||||
@Component
|
||||
public class TrackedEmoteRunTimeStorage {
|
||||
/**
|
||||
* A map of *minutes* containing a map of server_ids containing a list of {@link PersistingEmote}, which contains
|
||||
* all necessary information about the emotes which were used.
|
||||
* The top most map contains all the different minutes in which there were used emotes. Mostly this
|
||||
* map will not contain many keys, because the {@link dev.sheldan.abstracto.statistic.emotes.job.EmotePersistingJob}
|
||||
* will remove them a minute later. The Map within the current minute will contain every server as a key in which
|
||||
* there were emotes used in the particular minute. {@link PersistingEmote} does not contain any JDA related objects
|
||||
* but only the information necessary to identify any {@link net.dv8tion.jda.api.entities.Emote}.
|
||||
*/
|
||||
private HashMap<Long, Map<Long, List<PersistingEmote>>> trackedEmotes = new HashMap<>();
|
||||
|
||||
public Map<Long, Map<Long, List<PersistingEmote>>> getRuntimeConfig() {
|
||||
return trackedEmotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the minute has already been tracked.
|
||||
* @param key The minute since 1970 to check for
|
||||
* @return Whether or not the minute already has an entry
|
||||
*/
|
||||
public boolean contains(Long key) {
|
||||
return trackedEmotes.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the minute identified by the {@link Long} since 1970 into the Map, with the associated Map of server_ids and
|
||||
* {@link PersistingEmote}.
|
||||
* @param key The minute since 1970 to add
|
||||
* @param objectToPut The Map of server_ids mapping to List of {@link PersistingEmote} toa dd
|
||||
*/
|
||||
public void put(Long key, Map<Long, List<PersistingEmote>> objectToPut) {
|
||||
trackedEmotes.put(key, objectToPut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an entry identified by the minute since 1970
|
||||
* @param key The key of the minute to retrieve
|
||||
* @return The Map of server_ids and {@link PersistingEmote} which already exists for the given minute
|
||||
*/
|
||||
public Map<Long, List<PersistingEmote>> get(Long key) {
|
||||
return trackedEmotes.get(key);
|
||||
}
|
||||
|
||||
@@ -34,25 +34,33 @@ public class TrackedEmoteRuntimeServiceBean implements TrackedEmoteRuntimeServic
|
||||
public void addEmoteForServer(Emote emote, Guild guild, Long count, boolean external) {
|
||||
takeLock();
|
||||
try {
|
||||
// generate an appropriate key
|
||||
Long key = getKey();
|
||||
// create a PersistingEmote based the given Emote
|
||||
PersistingEmote newPersistentEmote = createFromEmote(guild, emote, count, external);
|
||||
if (trackedEmoteRunTimeStorage.contains(key)) {
|
||||
// if it already exists, we can add to the already existing map
|
||||
Map<Long, List<PersistingEmote>> elementsForKey = trackedEmoteRunTimeStorage.get(key);
|
||||
if (elementsForKey.containsKey(guild.getIdLong())) {
|
||||
// if the server already has an entry, we can just add it to the list of existing ones
|
||||
List<PersistingEmote> persistingEmotes = elementsForKey.get(guild.getIdLong());
|
||||
Optional<PersistingEmote> existingEmote = persistingEmotes
|
||||
.stream()
|
||||
.filter(persistingEmote -> persistingEmote.getEmoteId().equals(emote.getIdLong()))
|
||||
.findFirst();
|
||||
// if it exists already, just increment the counter by the given amount
|
||||
existingEmote.ifPresent(persistingEmote -> persistingEmote.setCount(persistingEmote.getCount() + count));
|
||||
if (!existingEmote.isPresent()) {
|
||||
// just add the newly created one
|
||||
persistingEmotes.add(newPersistentEmote);
|
||||
}
|
||||
} else {
|
||||
// it did not exist for the server, create a new list of PersistingEmote
|
||||
log.trace("Adding emote {} to list of server {}.", newPersistentEmote.getEmoteId(), guild.getIdLong());
|
||||
elementsForKey.put(guild.getIdLong(), new ArrayList<>(Arrays.asList(newPersistentEmote)));
|
||||
}
|
||||
} else {
|
||||
// no entry for the minute exists yet, add a new one
|
||||
HashMap<Long, List<PersistingEmote>> serverEmotes = new HashMap<>();
|
||||
serverEmotes.put(guild.getIdLong(), new ArrayList<>(Arrays.asList(newPersistentEmote)));
|
||||
log.trace("Adding emote map entry for server {}.", guild.getIdLong());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteOverview;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteSynchronizationResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,6 +52,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, guild.getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
emotes.forEach(emote -> {
|
||||
boolean emoteIsFromGuild = emoteService.emoteIsFromGuild(emote, guild);
|
||||
// either the emote is from the current guild (we always add those) or external emote tracking is enabled (we should always add those)
|
||||
if(externalTrackingEnabled || emoteIsFromGuild) {
|
||||
trackedEmoteRuntimeService.addEmoteForServer(emote, guild, !emoteIsFromGuild);
|
||||
}
|
||||
@@ -62,6 +63,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
public void addEmoteToRuntimeStorage(Emote emote, Guild guild, Long count) {
|
||||
boolean externalTrackingEnabled = featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, guild.getIdLong(), EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
boolean emoteIsFromGuild = emoteService.emoteIsFromGuild(emote, guild);
|
||||
// either the emote is from the current guild (we always add those) or external emote tracking is enabled (we should always add those)
|
||||
if(externalTrackingEnabled || emoteIsFromGuild) {
|
||||
trackedEmoteRuntimeService.addEmoteForServer(emote, guild, count, !emoteIsFromGuild);
|
||||
}
|
||||
@@ -77,36 +79,41 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
persistingEmotes.forEach(persistingEmote -> {
|
||||
Optional<TrackedEmote> emoteOptional = trackedEmoteManagementService.loadByEmoteIdOptional(persistingEmote.getEmoteId(), serverId);
|
||||
emoteOptional.ifPresent(trackedEmote -> {
|
||||
// only track the record, if its enabled
|
||||
if(trackedEmote.getTrackingEnabled()) {
|
||||
Optional<UsedEmote> existingUsedEmote = usedEmoteManagementService.loadUsedEmoteForTrackedEmoteToday(trackedEmote);
|
||||
// if a use for today already exists, increment the amount
|
||||
existingUsedEmote.ifPresent(usedEmote ->
|
||||
usedEmote.setAmount(usedEmote.getAmount() + persistingEmote.getCount())
|
||||
);
|
||||
// if none exists, create a new
|
||||
if(!existingUsedEmote.isPresent()) {
|
||||
usedEmoteManagementService.createEmoteUsageForToday(trackedEmote, persistingEmote.getCount());
|
||||
}
|
||||
} else {
|
||||
log.trace("Tracking disabled for emote {} in server {}.", trackedEmote.getTrackedEmoteId().getEmoteId(), trackedEmote.getTrackedEmoteId().getServerId());
|
||||
log.trace("Tracking disabled for emote {} in server {}.", trackedEmote.getTrackedEmoteId().getId(), trackedEmote.getTrackedEmoteId().getServerId());
|
||||
}
|
||||
});
|
||||
if(!emoteOptional.isPresent()) {
|
||||
createNewTrackedEmote(serverId, autoTrackExternalEmotes, trackExternalEmotes, persistingEmote);
|
||||
// if tracked emote does not exists, we might want to create one (only for external emotes)
|
||||
// we only do it for external emotes, because the feature mode AUTO_TRACK would not make sense
|
||||
// we might want emotes which are completely ignored by emote tracking
|
||||
if(!emoteOptional.isPresent() && autoTrackExternalEmotes && trackExternalEmotes) {
|
||||
createNewTrackedEmote(serverId, persistingEmote);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void createNewTrackedEmote(Long serverId, boolean autoTrackExternalEmotes, boolean trackExternalEmotes, PersistingEmote persistingEmote) {
|
||||
/**
|
||||
* Creates a new {@link TrackedEmote} from the given {@link PersistingEmote}.
|
||||
* @param serverId The ID of the {@link dev.sheldan.abstracto.core.models.database.AServer} for which the {@link TrackedEmote} should be created for
|
||||
* @param persistingEmote The {@link PersistingEmote} which contains all information necessary to create a {@link TrackedEmote}
|
||||
*/
|
||||
private void createNewTrackedEmote(Long serverId, PersistingEmote persistingEmote) {
|
||||
Optional<Guild> guildOptional = botService.getGuildByIdOptional(serverId);
|
||||
guildOptional.ifPresent(guild -> {
|
||||
Emote emoteFromGuild = guild.getEmoteById(persistingEmote.getEmoteId());
|
||||
if(emoteFromGuild != null) {
|
||||
TrackedEmote newCreatedTrackedEmote = trackedEmoteManagementService.createTrackedEmote(emoteFromGuild, guild);
|
||||
usedEmoteManagementService.createEmoteUsageForToday(newCreatedTrackedEmote, persistingEmote.getCount());
|
||||
} else if(autoTrackExternalEmotes && trackExternalEmotes){
|
||||
TrackedEmote newCreatedTrackedEmote = trackedEmoteManagementService.createExternalEmote(persistingEmote);
|
||||
usedEmoteManagementService.createEmoteUsageForToday(newCreatedTrackedEmote, persistingEmote.getCount());
|
||||
}
|
||||
TrackedEmote newCreatedTrackedEmote = trackedEmoteManagementService.createExternalTrackedEmote(persistingEmote);
|
||||
usedEmoteManagementService.createEmoteUsageForToday(newCreatedTrackedEmote, persistingEmote.getCount());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -116,10 +123,10 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote getFakeTrackedEmote(Long id, Guild guild) {
|
||||
public TrackedEmote getFakeTrackedEmote(Long emoteId, Guild guild) {
|
||||
return TrackedEmote
|
||||
.builder()
|
||||
.trackedEmoteId(new TrackedEmoteServer(id, guild.getIdLong()))
|
||||
.trackedEmoteId(new ServerSpecificId(guild.getIdLong(), emoteId))
|
||||
.fake(true)
|
||||
.build();
|
||||
}
|
||||
@@ -130,21 +137,26 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
Long addedEmotes = 0L;
|
||||
List<Emote> allExistingEmotes = guild.getEmotes();
|
||||
log.info("Synchronizing emotes for server {}, currently tracked emotes {}, available emotes for server {}.", guild.getIdLong(), activeTrackedEmotes.size(), allExistingEmotes.size());
|
||||
// iterate over all emotes currently available in the guild
|
||||
for (Emote emote : allExistingEmotes) {
|
||||
// find the emote in the list of known TrackedEmote
|
||||
Optional<TrackedEmote> trackedEmoteOptional = activeTrackedEmotes
|
||||
.stream()
|
||||
.filter(trackedEmote ->
|
||||
trackedEmote.getTrackedEmoteId().getEmoteId().equals(emote.getIdLong())
|
||||
trackedEmote.getTrackedEmoteId().getId().equals(emote.getIdLong())
|
||||
&& trackedEmote.getTrackedEmoteId().getServerId().equals(guild.getIdLong()))
|
||||
.findFirst();
|
||||
// if its not present, create it
|
||||
if (!trackedEmoteOptional.isPresent()) {
|
||||
trackedEmoteManagementService.createTrackedEmote(emote, guild);
|
||||
addedEmotes++;
|
||||
} else {
|
||||
// if we know it, remove it from the current tracked emotes
|
||||
activeTrackedEmotes.remove(trackedEmoteOptional.get());
|
||||
}
|
||||
}
|
||||
|
||||
// the ones which are still around here, were not found in the emotes retrieved from the guild, we can mark them as deleted
|
||||
activeTrackedEmotes.forEach(trackedEmote ->
|
||||
trackedEmoteManagementService.markAsDeleted(trackedEmote)
|
||||
);
|
||||
@@ -171,13 +183,13 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createFakeTrackedEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild) {
|
||||
boolean external = !emoteService.emoteIsFromGuild(emote, guild);
|
||||
return createFakeTrackedEmote(emote, guild, external);
|
||||
return createTrackedEmote(emote, guild, external);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createFakeTrackedEmote(Emote emote, Guild guild, boolean external) {
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
|
||||
return trackedEmoteManagementService.createTrackedEmote(emote, guild, external);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class UsedEmoteServiceBean implements UsedEmoteService {
|
||||
|
||||
@Override
|
||||
public void purgeEmoteUsagesSince(TrackedEmote emote, Instant since) {
|
||||
log.info("Purging emote {} in server {} since {}.", emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId(), since);
|
||||
log.info("Purging emote {} in server {} since {}.", emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId(), since);
|
||||
usedEmoteManagementService.purgeEmoteUsagesSince(emote, since.truncatedTo(ChronoUnit.DAYS));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.PersistingEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.repository.TrackedEmoteRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -40,7 +40,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
|
||||
if(external) {
|
||||
return createExternalEmote(emote, guild);
|
||||
return createExternalTrackedEmote(emote, guild);
|
||||
} else {
|
||||
return createTrackedEmote(emote, guild);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
TrackedEmote emote = TrackedEmote
|
||||
.builder()
|
||||
.animated(animated)
|
||||
.trackedEmoteId(new TrackedEmoteServer(emoteId, server.getId()))
|
||||
.trackedEmoteId(new ServerSpecificId(server.getId(), emoteId))
|
||||
.trackingEnabled(tracked)
|
||||
.emoteName(emoteName)
|
||||
.server(server)
|
||||
@@ -63,11 +63,11 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createExternalEmote(Long emoteId, String emoteName, String externalUrl, Boolean animated, AServer server) {
|
||||
public TrackedEmote createExternalEmote(Long emoteId, String emoteName, String externalUrl, Boolean animated, AServer server, boolean trackingEnabled) {
|
||||
TrackedEmote emote = TrackedEmote
|
||||
.builder()
|
||||
.animated(animated)
|
||||
.trackedEmoteId(new TrackedEmoteServer(emoteId, server.getId()))
|
||||
.trackedEmoteId(new ServerSpecificId(server.getId(), emoteId))
|
||||
.trackingEnabled(true)
|
||||
.deleted(false)
|
||||
.emoteName(emoteName)
|
||||
@@ -85,15 +85,15 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createExternalEmote(PersistingEmote persistingEmote) {
|
||||
public TrackedEmote createExternalTrackedEmote(PersistingEmote persistingEmote) {
|
||||
AServer server = serverManagementService.loadServer(persistingEmote.getServerId());
|
||||
return createExternalEmote(persistingEmote.getEmoteId(), persistingEmote.getEmoteName(), persistingEmote.getExternalUrl(), persistingEmote.getAnimated(), server);
|
||||
return createExternalEmote(persistingEmote.getEmoteId(), persistingEmote.getEmoteName(), persistingEmote.getExternalUrl(), persistingEmote.getAnimated(), server, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createExternalEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote createExternalTrackedEmote(Emote emote, Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild.getIdLong());
|
||||
return createExternalEmote(emote.getIdLong(), emote.getName(), emote.getImageUrl(), emote.isAnimated(), server);
|
||||
return createExternalEmote(emote.getIdLong(), emote.getName(), emote.getImageUrl(), emote.isAnimated(), server, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +104,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(TrackedEmote trackedemote) {
|
||||
log.info("Marking tracked emote {} in server {} as deleted.", trackedemote.getTrackedEmoteId().getEmoteId(), trackedemote.getTrackedEmoteId().getServerId());
|
||||
log.info("Marking tracked emote {} in server {} as deleted.", trackedemote.getTrackedEmoteId().getId(), trackedemote.getTrackedEmoteId().getServerId());
|
||||
trackedemote.setDeleted(true);
|
||||
}
|
||||
|
||||
@@ -124,13 +124,13 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote loadByTrackedEmoteServer(TrackedEmoteServer trackedEmoteServer) {
|
||||
return loadByEmoteId(trackedEmoteServer.getEmoteId(), trackedEmoteServer.getServerId());
|
||||
public TrackedEmote loadByTrackedEmoteServer(ServerSpecificId trackedEmoteServer) {
|
||||
return loadByEmoteId(trackedEmoteServer.getId(), trackedEmoteServer.getServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TrackedEmote> loadByEmoteIdOptional(Long emoteId, Long serverId) {
|
||||
return repository.findById(new TrackedEmoteServer(emoteId, serverId));
|
||||
return repository.findById(new ServerSpecificId(serverId, emoteId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,25 +154,25 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
|
||||
@Override
|
||||
public void changeName(TrackedEmote emote, String newName) {
|
||||
log.info("Changing name of emote {} in server {}.", emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId());
|
||||
log.info("Changing name of emote {} in server {}.", emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId());
|
||||
emote.setEmoteName(newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableTrackedEmote(TrackedEmote emote) {
|
||||
log.info("Disabling tracking for tracked emote {} in server {}.", emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId());
|
||||
log.info("Disabling tracking for tracked emote {} in server {}.", emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId());
|
||||
emote.setTrackingEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableTrackedEmote(TrackedEmote emote) {
|
||||
log.info("Enabling tracking for tracked emote {} in server {}.", emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId());
|
||||
log.info("Enabling tracking for tracked emote {} in server {}.", emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId());
|
||||
emote.setTrackingEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrackedEmote(TrackedEmote emote) {
|
||||
log.info("Deleting tracked emote {} in server {}.", emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId());
|
||||
log.info("Deleting tracked emote {} in server {}.", emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId());
|
||||
repository.delete(emote);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,17 +23,17 @@ public class UsedEmoteManagementServiceBean implements UsedEmoteManagementServic
|
||||
|
||||
@Override
|
||||
public Optional<UsedEmote> loadUsedEmoteForTrackedEmoteToday(TrackedEmote trackedEmote) {
|
||||
return usedEmoteRepository.findEmoteFromServerToday(trackedEmote.getTrackedEmoteId().getEmoteId() , trackedEmote.getTrackedEmoteId().getServerId());
|
||||
return usedEmoteRepository.findEmoteFromServerToday(trackedEmote.getTrackedEmoteId().getId(), trackedEmote.getTrackedEmoteId().getServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsedEmote createEmoteUsageForToday(TrackedEmote trackedEmote, Long count) {
|
||||
UsedEmote usedEmote = UsedEmote
|
||||
.builder()
|
||||
.emoteId(new UsedEmoteDay(trackedEmote.getTrackedEmoteId().getEmoteId(), trackedEmote.getTrackedEmoteId().getServerId(), Instant.now()))
|
||||
.emoteId(new UsedEmoteDay(trackedEmote.getTrackedEmoteId().getId(), trackedEmote.getTrackedEmoteId().getServerId(), Instant.now()))
|
||||
.amount(count)
|
||||
.build();
|
||||
log.trace("Creating emote usage for emote {} in server {} with count {}.", trackedEmote.getTrackedEmoteId().getEmoteId(), trackedEmote.getTrackedEmoteId().getServerId(), count);
|
||||
log.trace("Creating emote usage for emote {} in server {} with count {}.", trackedEmote.getTrackedEmoteId().getId(), trackedEmote.getTrackedEmoteId().getServerId(), count);
|
||||
return usedEmoteRepository.save(usedEmote);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,6 @@ public class UsedEmoteManagementServiceBean implements UsedEmoteManagementServic
|
||||
|
||||
@Override
|
||||
public void purgeEmoteUsagesSince(TrackedEmote emote, Instant since) {
|
||||
usedEmoteRepository.deleteByEmoteId_EmoteIdAndEmoteId_ServerIdAndEmoteId_UseDateGreaterThan(emote.getTrackedEmoteId().getEmoteId(), emote.getTrackedEmoteId().getServerId(), since);
|
||||
usedEmoteRepository.deleteByEmoteId_EmoteIdAndEmoteId_ServerIdAndEmoteId_UseDateGreaterThan(emote.getTrackedEmoteId().getId(), emote.getTrackedEmoteId().getServerId(), since);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,9 @@
|
||||
<column name="name" value="statistic"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="module">
|
||||
<column name="name" value="emoteTracking"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -3,11 +3,11 @@ 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.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import org.junit.Assert;
|
||||
@@ -47,7 +47,7 @@ public class DeleteTrackedEmoteTest {
|
||||
@Test
|
||||
public void testExecuteWithExistingTrackedEmote() {
|
||||
TrackedEmote fakedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(1L, 1L);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(1L, 1L);
|
||||
when(fakedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(trackedEmoteServer)).thenReturn(actualTrackedEmote);
|
||||
@@ -59,7 +59,7 @@ public class DeleteTrackedEmoteTest {
|
||||
@Test(expected = TrackedEmoteNotFoundException.class)
|
||||
public void testExecuteNonExistingTrackedEmote() {
|
||||
TrackedEmote fakedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(1L, 1L);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(1L, 1L);
|
||||
when(fakedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(trackedEmoteServer)).thenThrow(new TrackedEmoteNotFoundException());
|
||||
testUnit.execute(CommandTestUtilities.getWithParameters(Arrays.asList(fakedEmote)));
|
||||
|
||||
@@ -2,10 +2,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.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import org.junit.Assert;
|
||||
@@ -49,7 +49,7 @@ public class DisableEmoteTrackingTest {
|
||||
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote));
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmoteServer trackedEmoteServer = Mockito.mock(TrackedEmoteServer.class);
|
||||
ServerSpecificId trackedEmoteServer = Mockito.mock(ServerSpecificId.class);
|
||||
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(trackedEmoteServer)).thenReturn(actualTrackedEmote);
|
||||
testUnit.execute(commandContext);
|
||||
|
||||
@@ -2,10 +2,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.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.UsedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import org.junit.Assert;
|
||||
@@ -43,7 +43,7 @@ public class PurgeEmoteStatsTest {
|
||||
public void testPurgeEntireTimeLineOfEmote() {
|
||||
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmoteServer trackedEmoteServer = Mockito.mock(TrackedEmoteServer.class);
|
||||
ServerSpecificId trackedEmoteServer = Mockito.mock(ServerSpecificId.class);
|
||||
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(trackedEmoteServer)).thenReturn(actualTrackedEmote);
|
||||
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote));
|
||||
@@ -56,7 +56,7 @@ public class PurgeEmoteStatsTest {
|
||||
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote, Duration.ofHours(4)));
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmoteServer trackedEmoteServer = Mockito.mock(TrackedEmoteServer.class);
|
||||
ServerSpecificId trackedEmoteServer = Mockito.mock(ServerSpecificId.class);
|
||||
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(trackedEmoteServer)).thenReturn(actualTrackedEmote);
|
||||
testUnit.execute(commandContext);
|
||||
|
||||
@@ -5,12 +5,12 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameterTypeExcept
|
||||
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.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -53,7 +53,7 @@ public class ShowExternalTrackedEmoteTest {
|
||||
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(actualTrackedEmote.getExternal()).thenReturn(true);
|
||||
TrackedEmoteServer trackedEmoteServer = Mockito.mock(TrackedEmoteServer.class);
|
||||
ServerSpecificId trackedEmoteServer = Mockito.mock(ServerSpecificId.class);
|
||||
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId())).thenReturn(actualTrackedEmote);
|
||||
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote));
|
||||
@@ -67,7 +67,7 @@ public class ShowExternalTrackedEmoteTest {
|
||||
TrackedEmote fakeTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
TrackedEmote actualTrackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(actualTrackedEmote.getExternal()).thenReturn(false);
|
||||
TrackedEmoteServer trackedEmoteServer = Mockito.mock(TrackedEmoteServer.class);
|
||||
ServerSpecificId trackedEmoteServer = Mockito.mock(ServerSpecificId.class);
|
||||
when(fakeTrackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteManagementService.loadByTrackedEmoteServer(fakeTrackedEmote.getTrackedEmoteId())).thenReturn(actualTrackedEmote);
|
||||
CommandContext commandContext = CommandTestUtilities.getWithParameters(Arrays.asList(fakeTrackedEmote));
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.core.command.exception.InsufficientParametersExcept
|
||||
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.CommandTestUtilities;
|
||||
@@ -13,7 +14,6 @@ import dev.sheldan.abstracto.statistic.config.StatisticFeatures;
|
||||
import dev.sheldan.abstracto.statistic.emotes.command.parameter.TrackEmoteParameter;
|
||||
import dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.TrackedEmoteService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -69,7 +69,7 @@ public class TrackEmoteTest {
|
||||
when(trackedEmoteManagementService.trackedEmoteExists(EMOTE_ID, SERVER_ID)).thenReturn(true);
|
||||
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
when(trackedEmoteManagementService.loadByEmoteId(EMOTE_ID, SERVER_ID)).thenReturn(trackedEmote);
|
||||
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
|
||||
CommandResult result = testUnit.execute(commandContext);
|
||||
@@ -83,7 +83,7 @@ public class TrackEmoteTest {
|
||||
when(trackedEmoteManagementService.trackedEmoteExists(EMOTE_ID, SERVER_ID)).thenReturn(false);
|
||||
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
Emote emoteToTrack = Mockito.mock(Emote.class);
|
||||
when(trackEmoteParameter.getEmote()).thenReturn(emoteToTrack);
|
||||
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
|
||||
@@ -98,14 +98,14 @@ public class TrackEmoteTest {
|
||||
when(trackedEmoteManagementService.trackedEmoteExists(EMOTE_ID, SERVER_ID)).thenReturn(false);
|
||||
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
Emote emoteToTrack = Mockito.mock(Emote.class);
|
||||
when(trackEmoteParameter.getEmote()).thenReturn(emoteToTrack);
|
||||
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
|
||||
when(emoteService.emoteIsFromGuild(emoteToTrack, commandContext.getGuild())).thenReturn(false);
|
||||
CommandResult result = testUnit.execute(commandContext);
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
verify(trackedEmoteService, times(1)).createFakeTrackedEmote(emoteToTrack, commandContext.getGuild(), true);
|
||||
verify(trackedEmoteService, times(1)).createTrackedEmote(emoteToTrack, commandContext.getGuild(), true);
|
||||
verify(featureModeService, times(1)).validateActiveFeatureMode(SERVER_ID, StatisticFeatures.EMOTE_TRACKING, EmoteTrackingMode.EXTERNAL_EMOTES);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class TrackEmoteTest {
|
||||
when(trackedEmoteManagementService.trackedEmoteExists(EMOTE_ID, SERVER_ID)).thenReturn(false);
|
||||
when(commandContext.getGuild().getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
when(trackEmoteParameter.getTrackedEmote()).thenReturn(trackedEmote);
|
||||
testUnit.execute(commandContext);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.converter;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
@@ -84,11 +84,11 @@ public class EmoteStatsConverterTest {
|
||||
when(trackedEmote.getExternal()).thenReturn(false);
|
||||
when(trackedEmote.getAnimated()).thenReturn(false);
|
||||
when(trackedEmote.getDeleted()).thenReturn(false);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
when(trackedEmote2.getExternal()).thenReturn(false);
|
||||
when(trackedEmote2.getAnimated()).thenReturn(true);
|
||||
when(trackedEmote2.getDeleted()).thenReturn(false);
|
||||
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID_2, SERVER_ID));
|
||||
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID_2));
|
||||
when(botService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
Emote emote1 = Mockito.mock(Emote.class);
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(emote1);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteOverview;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.TrackedEmoteSynchronizationResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.TrackedEmoteManagementService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -70,7 +70,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
private TrackedEmote trackedEmote2;
|
||||
|
||||
@Mock
|
||||
private TrackedEmoteServer trackedEmoteServer;
|
||||
private ServerSpecificId trackedEmoteServer;
|
||||
|
||||
@Mock
|
||||
private TrackedEmote secondTrackedEmote;
|
||||
@@ -85,7 +85,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
private UsedEmote usedEmote;
|
||||
|
||||
@Mock
|
||||
private TrackedEmoteServer secondTrackedEmoteServer;
|
||||
private ServerSpecificId secondTrackedEmoteServer;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Emote> emoteArgumentCaptor;
|
||||
@@ -197,7 +197,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote fakeTrackedEmote = testUnit.getFakeTrackedEmote(emote, guild);
|
||||
Assert.assertTrue(fakeTrackedEmote.isFake());
|
||||
Assert.assertEquals(EMOTE_ID, fakeTrackedEmote.getTrackedEmoteId().getEmoteId());
|
||||
Assert.assertEquals(EMOTE_ID, fakeTrackedEmote.getTrackedEmoteId().getId());
|
||||
Assert.assertEquals(SERVER_ID, fakeTrackedEmote.getTrackedEmoteId().getServerId());
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmote fakedTrackedEmote = testUnit.getFakeTrackedEmote(EMOTE_ID, guild);
|
||||
Assert.assertTrue(fakedTrackedEmote.isFake());
|
||||
Assert.assertEquals(EMOTE_ID, fakedTrackedEmote.getTrackedEmoteId().getEmoteId());
|
||||
Assert.assertEquals(EMOTE_ID, fakedTrackedEmote.getTrackedEmoteId().getId());
|
||||
Assert.assertEquals(SERVER_ID, fakedTrackedEmote.getTrackedEmoteId().getServerId());
|
||||
}
|
||||
|
||||
@@ -215,10 +215,10 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
|
||||
when(trackedEmoteServer.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteServer.getId()).thenReturn(EMOTE_ID);
|
||||
when(secondTrackedEmote.getTrackedEmoteId()).thenReturn(secondTrackedEmoteServer);
|
||||
when(secondTrackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
|
||||
when(secondTrackedEmoteServer.getEmoteId()).thenReturn(EMOTE_ID_2);
|
||||
when(secondTrackedEmoteServer.getId()).thenReturn(EMOTE_ID_2);
|
||||
when(guild.getEmotes()).thenReturn(Arrays.asList(emote, secondEmote));
|
||||
when(emote.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(secondEmote.getIdLong()).thenReturn(EMOTE_ID_2);
|
||||
@@ -235,7 +235,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
|
||||
when(trackedEmoteServer.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteServer.getId()).thenReturn(EMOTE_ID);
|
||||
when(guild.getEmotes()).thenReturn(Arrays.asList(emote, secondEmote));
|
||||
when(emote.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote)));
|
||||
@@ -251,7 +251,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
when(trackedEmoteServer.getServerId()).thenReturn(SERVER_ID);
|
||||
when(trackedEmoteServer.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteServer.getId()).thenReturn(EMOTE_ID);
|
||||
when(guild.getEmotes()).thenReturn(Arrays.asList(emote));
|
||||
when(emote.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(SERVER_ID)).thenReturn(new ArrayList<>(Arrays.asList(trackedEmote, secondTrackedEmote)));
|
||||
@@ -315,7 +315,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
usagesToStore.put(SERVER_ID, Arrays.asList(persistingEmote));
|
||||
when(persistingEmote.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.of(trackedEmote));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
when(trackedEmote.getTrackingEnabled()).thenReturn(false);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
@@ -350,29 +350,11 @@ public class TrackedEmoteServiceBeanTest {
|
||||
verify(usedEmoteManagementService, times(0)).createEmoteUsageForToday(any(TrackedEmote.class), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreStatisticOneServerInternalEmoteTrackingEnabledAutoTracking() {
|
||||
HashMap<Long, List<PersistingEmote>> usagesToStore = new HashMap<>();
|
||||
usagesToStore.put(SERVER_ID, Arrays.asList(persistingEmote));
|
||||
when(persistingEmote.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(botService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guild));
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(emote);
|
||||
when(persistingEmote.getCount()).thenReturn(COUNT);
|
||||
when(trackedEmoteManagementService.createTrackedEmote(emote, guild)).thenReturn(trackedEmote);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.empty());
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
testUnit.storeEmoteStatistics(usagesToStore);
|
||||
verify(usedEmoteManagementService, times(1)).createEmoteUsageForToday(trackedEmote, COUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreStatisticOneServerExternalEmoteTrackingEnabledAutoTrackingDisabledExternal() {
|
||||
HashMap<Long, List<PersistingEmote>> usagesToStore = new HashMap<>();
|
||||
usagesToStore.put(SERVER_ID, Arrays.asList(persistingEmote));
|
||||
when(persistingEmote.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(botService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guild));
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(null);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.empty());
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(false);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
@@ -386,10 +368,9 @@ public class TrackedEmoteServiceBeanTest {
|
||||
usagesToStore.put(SERVER_ID, Arrays.asList(persistingEmote));
|
||||
when(persistingEmote.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(botService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guild));
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(null);
|
||||
when(persistingEmote.getCount()).thenReturn(COUNT);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.empty());
|
||||
when(trackedEmoteManagementService.createExternalEmote(persistingEmote)).thenReturn(trackedEmote);
|
||||
when(trackedEmoteManagementService.createExternalTrackedEmote(persistingEmote)).thenReturn(trackedEmote);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
testUnit.storeEmoteStatistics(usagesToStore);
|
||||
@@ -401,29 +382,27 @@ public class TrackedEmoteServiceBeanTest {
|
||||
HashMap<Long, List<PersistingEmote>> usagesToStore = new HashMap<>();
|
||||
|
||||
usagesToStore.put(SERVER_ID, Arrays.asList(persistingEmote));
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.empty());
|
||||
when(botService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guild));
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(null);
|
||||
when(trackedEmote.getTrackingEnabled()).thenReturn(true);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID, SERVER_ID)).thenReturn(Optional.of(trackedEmote));
|
||||
when(persistingEmote.getEmoteId()).thenReturn(EMOTE_ID);
|
||||
when(persistingEmote.getCount()).thenReturn(COUNT);
|
||||
when(trackedEmoteManagementService.createExternalEmote(persistingEmote)).thenReturn(trackedEmote);
|
||||
when(usedEmoteManagementService.loadUsedEmoteForTrackedEmoteToday(trackedEmote)).thenReturn(Optional.of(usedEmote));
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, SERVER_ID, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
|
||||
Long serverId2 = SERVER_ID + 1;
|
||||
usagesToStore.put(serverId2, Arrays.asList(persistingEmote2));
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID_2, serverId2)).thenReturn(Optional.of(trackedEmote));
|
||||
when(trackedEmote.getTrackingEnabled()).thenReturn(true);
|
||||
when(trackedEmoteManagementService.loadByEmoteIdOptional(EMOTE_ID_2, serverId2)).thenReturn(Optional.of(trackedEmote2));
|
||||
when(trackedEmote2.getTrackingEnabled()).thenReturn(true);
|
||||
when(persistingEmote2.getEmoteId()).thenReturn(EMOTE_ID_2);
|
||||
when(persistingEmote2.getCount()).thenReturn(COUNT);
|
||||
when(usedEmote.getAmount()).thenReturn(COUNT);
|
||||
when(usedEmoteManagementService.loadUsedEmoteForTrackedEmoteToday(trackedEmote)).thenReturn(Optional.of(usedEmote));
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, serverId2, EmoteTrackingMode.AUTO_TRACK_EXTERNAL)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(StatisticFeatures.EMOTE_TRACKING, serverId2, EmoteTrackingMode.EXTERNAL_EMOTES)).thenReturn(true);
|
||||
|
||||
testUnit.storeEmoteStatistics(usagesToStore);
|
||||
|
||||
verify(usedEmoteManagementService, times(1)).createEmoteUsageForToday(eq(trackedEmote), anyLong());
|
||||
verify(usedEmoteManagementService, times(1)).createEmoteUsageForToday(eq(trackedEmote2), anyLong());
|
||||
verify(usedEmote, times(1)).setAmount(2 * COUNT);
|
||||
}
|
||||
|
||||
@@ -439,7 +418,7 @@ public class TrackedEmoteServiceBeanTest {
|
||||
|
||||
private void executeCreateFakeTrackedEmoteTest(boolean external) {
|
||||
when(emoteService.emoteIsFromGuild(emote, guild)).thenReturn(!external);
|
||||
testUnit.createFakeTrackedEmote(emote, guild);
|
||||
testUnit.createTrackedEmote(emote, guild);
|
||||
verify(trackedEmoteManagementService, times(1)).createTrackedEmote(emote, guild, external);
|
||||
}
|
||||
|
||||
@@ -483,8 +462,8 @@ public class TrackedEmoteServiceBeanTest {
|
||||
when(trackedEmote2.getDeleted()).thenReturn(false);
|
||||
when(trackedEmote2.getExternal()).thenReturn(false);
|
||||
when(trackedEmote2.getAnimated()).thenReturn(true);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID_2, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
when(trackedEmote2.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID_2));
|
||||
when(guild.getEmoteById(EMOTE_ID)).thenReturn(emote);
|
||||
Emote emote2 = Mockito.mock(Emote.class);
|
||||
when(guild.getEmoteById(EMOTE_ID_2)).thenReturn(emote2);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.converter.EmoteStatsConverter;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsModel;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.service.management.UsedEmoteManagementService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -86,14 +86,14 @@ public class UsedEmoteServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testPurgeEmoteUsagesSince() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.purgeEmoteUsagesSince(trackedEmote, pointInTime);
|
||||
verify(usedEmoteManagementService, times(1)).purgeEmoteUsagesSince(trackedEmote, pointInTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeEmoteUsages() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.purgeEmoteUsages(trackedEmote);
|
||||
verify(usedEmoteManagementService, times(1)).purgeEmoteUsagesSince(trackedEmote, Instant.EPOCH);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.PersistingEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.repository.TrackedEmoteRepository;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
@@ -76,7 +76,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
@Test
|
||||
public void testCreateExternalEmote() {
|
||||
when(server.getId()).thenReturn(SERVER_ID);
|
||||
testUnit.createExternalEmote(EMOTE_ID, EMOTE_NAME, EXTERNAL_URL, ANIMATED, server);
|
||||
testUnit.createExternalEmote(EMOTE_ID, EMOTE_NAME, EXTERNAL_URL, ANIMATED, server, true);
|
||||
verifyEmoteCreation(true, true, EXTERNAL_URL);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
when(persistingEmote.getEmoteName()).thenReturn(EMOTE_NAME);
|
||||
when(persistingEmote.getAnimated()).thenReturn(ANIMATED);
|
||||
when(persistingEmote.getExternalUrl()).thenReturn(EXTERNAL_URL);
|
||||
testUnit.createExternalEmote(persistingEmote);
|
||||
testUnit.createExternalTrackedEmote(persistingEmote);
|
||||
verifyEmoteCreation(true, true, EXTERNAL_URL);
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
when(server.getId()).thenReturn(SERVER_ID);
|
||||
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||
testUnit.createExternalEmote(emote, guild);
|
||||
testUnit.createExternalTrackedEmote(emote, guild);
|
||||
verifyEmoteCreation(true, true, EXTERNAL_URL);
|
||||
}
|
||||
|
||||
public void verifyEmoteCreation(boolean tracked, boolean external, String externalUrl) {
|
||||
verify(repository, times(1)).save(trackedEmoteArgumentCaptor.capture());
|
||||
TrackedEmote createdTrackedEmote = trackedEmoteArgumentCaptor.getValue();
|
||||
Assert.assertEquals(EMOTE_ID, createdTrackedEmote.getTrackedEmoteId().getEmoteId());
|
||||
Assert.assertEquals(EMOTE_ID, createdTrackedEmote.getTrackedEmoteId().getId());
|
||||
Assert.assertEquals(SERVER_ID, createdTrackedEmote.getTrackedEmoteId().getServerId());
|
||||
Assert.assertEquals(EMOTE_NAME, createdTrackedEmote.getEmoteName());
|
||||
Assert.assertEquals(ANIMATED, createdTrackedEmote.getAnimated());
|
||||
@@ -155,7 +155,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testMarkAsDeleted() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
testUnit.markAsDeleted(trackedEmote);
|
||||
verify(trackedEmote, times(1)).setDeleted(true);
|
||||
@@ -163,7 +163,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testMarkAsDeletedId() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.of(trackedEmote));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(trackedEmoteServer);
|
||||
testUnit.markAsDeleted(SERVER_ID, EMOTE_ID);
|
||||
@@ -175,7 +175,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
when(emote.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(emote.getGuild()).thenReturn(guild);
|
||||
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.of(trackedEmote));
|
||||
TrackedEmote retrievedTrackedEmote = testUnit.loadByEmote(emote);
|
||||
Assert.assertEquals(trackedEmote, retrievedTrackedEmote);
|
||||
@@ -183,7 +183,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testLoadByEmoteId() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.of(trackedEmote));
|
||||
TrackedEmote retrievedEmote = testUnit.loadByEmoteId(EMOTE_ID, SERVER_ID);
|
||||
Assert.assertEquals(trackedEmote, retrievedEmote);
|
||||
@@ -191,14 +191,14 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test(expected = AbstractoRunTimeException.class)
|
||||
public void testLoadByEmoteIdNotFound() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.empty());
|
||||
testUnit.loadByEmoteId(EMOTE_ID, SERVER_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrackedEmoteExists() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.of(trackedEmote));
|
||||
boolean exists = testUnit.trackedEmoteExists(EMOTE_ID, SERVER_ID);
|
||||
Assert.assertTrue(exists);
|
||||
@@ -206,7 +206,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testTrackedEmoteExistsNot() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.empty());
|
||||
boolean exists = testUnit.trackedEmoteExists(EMOTE_ID, SERVER_ID);
|
||||
Assert.assertFalse(exists);
|
||||
@@ -214,7 +214,7 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testLoadByTrackedEmoteServer() {
|
||||
TrackedEmoteServer trackedEmoteServer = new TrackedEmoteServer(EMOTE_ID, SERVER_ID);
|
||||
ServerSpecificId trackedEmoteServer = new ServerSpecificId(SERVER_ID, EMOTE_ID);
|
||||
when(repository.findById(trackedEmoteServer)).thenReturn(Optional.of(trackedEmote));
|
||||
TrackedEmote retrievedTrackedEmote = testUnit.loadByTrackedEmoteServer(trackedEmoteServer);
|
||||
Assert.assertEquals(trackedEmote, retrievedTrackedEmote);
|
||||
@@ -255,28 +255,28 @@ public class TrackedEmoteManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testSetName() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.changeName(trackedEmote, EMOTE_NAME);
|
||||
verify(trackedEmote, times(1)).setEmoteName(EMOTE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableTrackedEmote() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.disableTrackedEmote(trackedEmote);
|
||||
verify(trackedEmote, times(1)).setTrackingEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableTrackedEmote() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.enableTrackedEmote(trackedEmote);
|
||||
verify(trackedEmote, times(1)).setTrackingEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTrackedEmote() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
testUnit.deleteTrackedEmote(trackedEmote);
|
||||
verify(repository, times(1)).delete(trackedEmote);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.EmoteStatsResult;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.repository.UsedEmoteRepository;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -129,7 +129,7 @@ public class UsedEmoteManagementServiceBeanTest {
|
||||
}
|
||||
|
||||
private void setupTrackedEmote() {
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new TrackedEmoteServer(EMOTE_ID, SERVER_ID));
|
||||
when(trackedEmote.getTrackedEmoteId()).thenReturn(new ServerSpecificId(SERVER_ID, EMOTE_ID));
|
||||
}
|
||||
|
||||
private void setupServer() {
|
||||
|
||||
@@ -2,10 +2,16 @@ package dev.sheldan.abstracto.statistic.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
|
||||
/**
|
||||
* Features available in the statistic module.
|
||||
*/
|
||||
public enum StatisticFeatures implements FeatureEnum {
|
||||
/**
|
||||
* Feature responsible to track the emotes used in a message on a server.
|
||||
*/
|
||||
EMOTE_TRACKING("emote_tracking");
|
||||
|
||||
private String key;
|
||||
private final String key;
|
||||
|
||||
StatisticFeatures(String key) {
|
||||
this.key = key;
|
||||
|
||||
@@ -9,13 +9,24 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link FeatureConfig} implementation to define the EmoteTracking feature.
|
||||
*/
|
||||
@Component
|
||||
public class EmoteTrackingFeature implements FeatureConfig {
|
||||
|
||||
/**
|
||||
* {@link FeatureEnum} represents the feature uniquely
|
||||
*/
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return StatisticFeatures.EMOTE_TRACKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* This feature contains three feature modes. For explanation of them check {@link EmoteTrackingFeature}
|
||||
* @return list of {@link FeatureMode} handled by this feature.
|
||||
*/
|
||||
@Override
|
||||
public List<FeatureMode> getAvailableModes() {
|
||||
return Arrays.asList(EmoteTrackingMode.EXTERNAL_EMOTES, EmoteTrackingMode.AUTO_TRACK, EmoteTrackingMode.AUTO_TRACK_EXTERNAL);
|
||||
|
||||
@@ -3,6 +3,13 @@ package dev.sheldan.abstracto.statistic.emotes.config;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* {@link FeatureMode}s for {@link EmoteTrackingFeature}. These modes include:
|
||||
* AUTO_TRACK: This controls a listener which listens for the emote events of a server, and automatically creates/updates/marks as deleted instances in the database if the respective event happens
|
||||
* Influences:
|
||||
* EXTERNAL_EMOTES: Enables the tracking of emotes which are not from the server the feature is enabled in. This feature alone only enables to track emotes with the `trackEmote` command and makes the command `externalEmoteStats` (and more) available
|
||||
* AUTO_TRACK_EXTERNAL: Every external emote which is encountered in a message will be tracked (created and updated), only works in combination with EXTERNAL_MOTES
|
||||
*/
|
||||
@Getter
|
||||
public enum EmoteTrackingMode implements FeatureMode {
|
||||
AUTO_TRACK("emoteAutoTrack"), EXTERNAL_EMOTES("externalEmotes"), AUTO_TRACK_EXTERNAL("autoTrackExternal");
|
||||
|
||||
@@ -4,6 +4,10 @@ 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;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class TrackedEmoteNotFoundException extends AbstractoRunTimeException {
|
||||
/**
|
||||
* Exception which is cased in a case the {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} could not be found.
|
||||
* The cases for this are currently wrapped with exist checks, but it will be raised if you call the method directly.
|
||||
*/
|
||||
public class TrackedEmoteNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
public TrackedEmoteNotFoundException(String message) {
|
||||
super(message);
|
||||
@@ -10,4 +15,14 @@ public class TrackedEmoteNotFoundException extends AbstractoRunTimeException {
|
||||
|
||||
public TrackedEmoteNotFoundException() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "emote_stats_tracked_emote_not_found";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,20 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
/**
|
||||
* Model which is used to render in emotes for the command `showTrackedEmotes`, which still exist in the server.
|
||||
* This means there is a {@link Emote} instance available.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AvailableTrackedEmote {
|
||||
/**
|
||||
* The {@link Emote} instance of the {@link TrackedEmote} to show
|
||||
*/
|
||||
private Emote emote;
|
||||
/**
|
||||
* The original {@link TrackedEmote} instance from the server to show
|
||||
*/
|
||||
private TrackedEmote trackedEmote;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,31 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model used to render the file produced by `exportEmoteStats`
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DownloadEmoteStatsModel {
|
||||
/**
|
||||
* The {@link Guild} for which the emote stats are being exportet
|
||||
*/
|
||||
private Guild guild;
|
||||
/**
|
||||
* The date this export has been performed on
|
||||
*/
|
||||
private Instant downloadDate;
|
||||
/**
|
||||
* The {@link Instant} which was used as the cut-off point in time to retrieve the emote stats for
|
||||
*/
|
||||
private Instant statsSince;
|
||||
/**
|
||||
* The {@link Member} who requested the export
|
||||
*/
|
||||
private Member requester;
|
||||
/**
|
||||
* A list of {@link UsedEmote} which are part of the export
|
||||
*/
|
||||
private List<UsedEmote> emotes;
|
||||
}
|
||||
@@ -9,16 +9,32 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The model used to render a `*emoteStats` result. This is split up into animated and static emotes, and will only
|
||||
* represent one type of these three: still existing, deleted and external. A guild instance is added for convenience.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class EmoteStatsModel {
|
||||
/**
|
||||
* The list of {@link EmoteStatsResultDisplay} which represent the animated emotes from the result
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<EmoteStatsResultDisplay> animatedEmotes = new ArrayList<>();
|
||||
/**
|
||||
* The list of {@link EmoteStatsResultDisplay} which represent the static emotes from the result
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<EmoteStatsResultDisplay> staticEmotes = new ArrayList<>();
|
||||
/**
|
||||
* The server the emote stats have been retrieved for.
|
||||
*/
|
||||
private Guild guild;
|
||||
|
||||
/**
|
||||
* Whether or not this model contains *any* stats to render.
|
||||
*/
|
||||
public boolean areStatsAvailable() {
|
||||
return !animatedEmotes.isEmpty() || !staticEmotes.isEmpty();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.model;
|
||||
|
||||
/**
|
||||
* The interface used to fill with values from the emote stats query. This represents the grouped result consisting of:
|
||||
* the ID of the emote, the ID of the server and the amount of times this emote has been used in the server
|
||||
*/
|
||||
public interface EmoteStatsResult {
|
||||
/**
|
||||
* ID of the emote
|
||||
*/
|
||||
Long getEmoteId();
|
||||
|
||||
/**
|
||||
* ID of the server
|
||||
*/
|
||||
Long getServerId();
|
||||
|
||||
/**
|
||||
* Amount the emote with the ID has been used in the server with the ID
|
||||
*/
|
||||
Long getAmount();
|
||||
}
|
||||
|
||||
@@ -6,11 +6,25 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
/**
|
||||
* Model used to render the emote stats for various commands. This contains the concrete {@link Emote} (if available).
|
||||
* This is only the case for emotes from the server. For external and deleted emotes, only {@link EmoteStatsResultDisplay} and
|
||||
* {@link TrackedEmote} will be available.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class EmoteStatsResultDisplay {
|
||||
/**
|
||||
* The actual {@link Emote} from the server, if available. Not available for deleted and external emotes.
|
||||
*/
|
||||
private Emote emote;
|
||||
/**
|
||||
* The {@link EmoteStatsResult} for one particular emote, containing the amount of times the emote has been used.
|
||||
*/
|
||||
private EmoteStatsResult result;
|
||||
/**
|
||||
* An instance of {@link TrackedEmote} for which this result has been retrieved.
|
||||
*/
|
||||
private TrackedEmote trackedEmote;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,41 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* This model is used to store the usages of an {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} in runtime.
|
||||
* It does not store JDA related entities, but rather direct values.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class PersistingEmote {
|
||||
/**
|
||||
* The global unique ID of the {@link net.dv8tion.jda.api.entities.Emote}
|
||||
*/
|
||||
private Long emoteId;
|
||||
/**
|
||||
* The name of the {@link net.dv8tion.jda.api.entities.Emote} in Discord
|
||||
*/
|
||||
private String emoteName;
|
||||
/**
|
||||
* Whether or not the {@link net.dv8tion.jda.api.entities.Emote} is animated
|
||||
*/
|
||||
private Boolean animated;
|
||||
/**
|
||||
* Whether or not the emote is from the {@link net.dv8tion.jda.api.entities.Guild} the {@link net.dv8tion.jda.api.entities.Message}
|
||||
* has been received on
|
||||
*/
|
||||
private Boolean external;
|
||||
/**
|
||||
* Only if the emote is external: the URL where the source image of the {@link net.dv8tion.jda.api.entities.Emote} is stored on Discord servers
|
||||
*/
|
||||
private String externalUrl;
|
||||
/**
|
||||
* The amount of times the {@link net.dv8tion.jda.api.entities.Emote} has been used.
|
||||
*/
|
||||
private Long count;
|
||||
/**
|
||||
* The ID of the {@link net.dv8tion.jda.api.entities.Guild} on which the {@link net.dv8tion.jda.api.entities.Emote} has been used on
|
||||
*/
|
||||
private Long serverId;
|
||||
}
|
||||
|
||||
@@ -9,30 +9,61 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model used to render the currently tracked emotes of a {@link Guild}. They are split up into
|
||||
* the static/animated emotes from the server itself. The {@link net.dv8tion.jda.internal.requests.Route.Emotes}
|
||||
* which were previously on the server and (if enabled) all external {@link TrackedEmote} from the server.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class TrackedEmoteOverview {
|
||||
/**
|
||||
* A list of {@link AvailableTrackedEmote} containing the static emotes of the {@link Guild} this command has been executed for.
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<AvailableTrackedEmote> animatedEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of {@link AvailableTrackedEmote} containing the animated emotes of the {@link Guild} this command has been executed for.
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<AvailableTrackedEmote> staticEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of {@link TrackedEmote} containing the static emotes which were previously in the {@link Guild}, but have since been deleted
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<TrackedEmote> deletedStaticEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of {@link TrackedEmote} containing the animated emotes which were previously in the {@link Guild}, but have since been deleted
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<TrackedEmote> deletedAnimatedEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of {@link TrackedEmote} containing the static emotes which were used on the {@link Guild}, but are not from that {@link Guild}.
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<TrackedEmote> externalStaticEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A list of {@link TrackedEmote} containing the animated emotes which were used on the {@link Guild}, but are not from that {@link Guild}.
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<TrackedEmote> externalAnimatedEmotes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The {@link Guild} for which the {@link TrackedEmote}s have been retrieved.
|
||||
*/
|
||||
private Guild guild;
|
||||
|
||||
/**
|
||||
* Adds the {@link TrackedEmote} to the correct list in this model, depending on the properties of the tracked emote.
|
||||
* @param trackedEmote The {@link TrackedEmote} instance to add to the lists
|
||||
* @param guild The {@link Guild} in which trackedEmote is being tracked
|
||||
*/
|
||||
public void addTrackedEmote(TrackedEmote trackedEmote, Guild guild) {
|
||||
if(trackedEmote.getDeleted()) {
|
||||
if(trackedEmote.getAnimated()) {
|
||||
@@ -49,7 +80,7 @@ public class TrackedEmoteOverview {
|
||||
} else {
|
||||
AvailableTrackedEmote availableEmote = AvailableTrackedEmote
|
||||
.builder()
|
||||
.emote(guild.getEmoteById(trackedEmote.getTrackedEmoteId().getEmoteId()))
|
||||
.emote(guild.getEmoteById(trackedEmote.getTrackedEmoteId().getId()))
|
||||
.trackedEmote(trackedEmote)
|
||||
.build();
|
||||
if(trackedEmote.getAnimated()) {
|
||||
|
||||
@@ -4,10 +4,21 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Model containing the result of `syncTrackedEmotes`. The two numbers are the amount of {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote}
|
||||
* which were created and marked as deleted.
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class TrackedEmoteSynchronizationResult {
|
||||
/**
|
||||
* The amount of {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} which were created because of the synchronization
|
||||
*/
|
||||
private Long emotesAdded;
|
||||
/**
|
||||
* The amount of {@link dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote} which were marked as deleted because of the synchronization
|
||||
*/
|
||||
private Long emotesMarkedDeleted;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.Fakeable;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
@@ -10,6 +10,11 @@ import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* The instance of an emote which is being tracked by {@link dev.sheldan.abstracto.statistic.emotes.config.EmoteTrackingFeature}.
|
||||
* This represents an emote by its unique ID and the respective server its being tracked in. This emote might not be part of the server
|
||||
* and might have been deleted.
|
||||
*/
|
||||
@Builder
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@@ -23,28 +28,50 @@ import java.time.Instant;
|
||||
public class TrackedEmote implements Serializable, Fakeable {
|
||||
|
||||
@EmbeddedId
|
||||
private TrackedEmoteServer trackedEmoteId;
|
||||
private ServerSpecificId trackedEmoteId;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@MapsId("serverId")
|
||||
@JoinColumn(name = "server_id", referencedColumnName = "id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
/**
|
||||
* The name of the {@link net.dv8tion.jda.api.entities.Emote} which is the same how it is identified within Discord.
|
||||
*/
|
||||
@Column(name = "name", length = 32)
|
||||
private String emoteName;
|
||||
|
||||
/**
|
||||
* Whether or not the emote is animated.
|
||||
*/
|
||||
@Column(name = "animated")
|
||||
private Boolean animated;
|
||||
|
||||
/**
|
||||
* Whether or not the tracking for this emote is enabled. Tracking enabled means, that the listener counts the usages of this emote
|
||||
* in the *Messages*.
|
||||
*/
|
||||
@Column(name = "tracking_enabled")
|
||||
private Boolean trackingEnabled;
|
||||
|
||||
/**
|
||||
* Whether or not the emote has been deleted from the server. This is only relevant for emotes which originated from the server
|
||||
* the feature is being used in. This does not have any meaning for external emotes.
|
||||
*/
|
||||
@Column(name = "deleted")
|
||||
private Boolean deleted;
|
||||
|
||||
/**
|
||||
* Whether or not the emote was *not* from the server the feature is being used in. This means, that the emote is from a foreign server
|
||||
* and we cannot identify the true server this emote is from.
|
||||
*/
|
||||
@Column(name = "external")
|
||||
private Boolean external;
|
||||
|
||||
/**
|
||||
* The URL of the picture which is associated with the emote. This is only used for external emotes and only actively used when
|
||||
* a user wants to see the picture of the emote with the command `showExternalTrackedEmote`
|
||||
*/
|
||||
@Column(name = "external_url")
|
||||
private String externalUrl;
|
||||
|
||||
@@ -64,6 +91,12 @@ public class TrackedEmote implements Serializable, Fakeable {
|
||||
this.updated = Instant.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Some emotes are build on demand, and do not necessarily be persisted. This happens when the emote is being used as a
|
||||
* {@link dev.sheldan.abstracto.core.command.config.Parameter}.
|
||||
* If a command uses this as a parameter, it is advised to actually load the {@link TrackedEmote} before using it, because it
|
||||
* is not guaranteed that it actually exists.
|
||||
*/
|
||||
@Transient
|
||||
private boolean fake;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* An actual instance which has been used on a certain date with a certain amount.
|
||||
*/
|
||||
@Builder
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@@ -18,9 +21,15 @@ import javax.persistence.*;
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class UsedEmote {
|
||||
|
||||
/**
|
||||
* The unique identifier for the emote: the ID of the emote, the ID of the server it was used in, the *date* the emote was used on.
|
||||
*/
|
||||
@EmbeddedId
|
||||
private UsedEmoteDay emoteId;
|
||||
|
||||
/**
|
||||
* Reference to the {@link TrackedEmote} which was used at the given date
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumns(
|
||||
{
|
||||
@@ -29,6 +38,9 @@ public class UsedEmote {
|
||||
})
|
||||
private TrackedEmote trackedEmote;
|
||||
|
||||
/**
|
||||
* The amount this {@link TrackedEmote} has been used on this date
|
||||
*/
|
||||
@Column(name = "amount")
|
||||
private Long amount;
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.model.database.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Embeddable
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TrackedEmoteServer implements Serializable {
|
||||
|
||||
@Column(name = "id")
|
||||
private Long emoteId;
|
||||
@Column(name = "server_id")
|
||||
private Long serverId;
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import javax.persistence.Embeddable;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* This {@link Embeddable} is used to create the composite primary key of {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote}
|
||||
* which consists of the `emote_id` (long), `server_id` (long) and the `use_date` (date)
|
||||
*/
|
||||
@Embeddable
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -15,11 +19,21 @@ import java.time.Instant;
|
||||
@NoArgsConstructor
|
||||
public class UsedEmoteDay implements Serializable {
|
||||
|
||||
/**
|
||||
* The globally unique ID of the emote
|
||||
*/
|
||||
@Column(name = "emote_id")
|
||||
private Long emoteId;
|
||||
/**
|
||||
* The ID of the {@link net.dv8tion.jda.api.entities.Guild} where this emote is *tracked* in. This does not mean, that the emote originated from this server,
|
||||
* just that it is part of the tracked emotes of the server.
|
||||
*/
|
||||
@Column(name = "server_id")
|
||||
private Long serverId;
|
||||
|
||||
/**
|
||||
* The *day* the emote was used, this is represented as an {@link Instant} here, but in the actual database its only a date
|
||||
*/
|
||||
@Column(name = "use_date")
|
||||
private Instant useDate;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,20 @@ 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;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,68 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Service responsible for managing and containing the runtime storage for emote statistics
|
||||
*/
|
||||
public interface TrackedEmoteRuntimeService {
|
||||
|
||||
/**
|
||||
* Returns the current runtime configuration. You should acquire the lock with `takeLock` before.
|
||||
* @return The Map containing the current runtime emote stats
|
||||
*/
|
||||
Map<Long, Map<Long, List<PersistingEmote>>> getRuntimeConfig();
|
||||
|
||||
/**
|
||||
* Adds the given {@link Emote} used in the {@link Guild} to the runtime storage.
|
||||
* The necessary lock will be acquired by this method.
|
||||
* @param emote The {@link Emote} to add to the runtime storage
|
||||
* @param guild The {@link Guild} in which the {@link Emote} is used
|
||||
* @param external Whether or not the emote is external
|
||||
*/
|
||||
void addEmoteForServer(Emote emote, Guild guild, boolean external);
|
||||
|
||||
/**
|
||||
* Adds the given {@link Emote} used in the {@link Guild} to the runtime storage.
|
||||
* The necessary lock will be acquired by this method.
|
||||
* @param emote The {@link Emote} to add to the runtime storage
|
||||
* @param guild The {@link Guild} in which the {@link Emote} is used
|
||||
* @param count The amount of usages which should be added
|
||||
* @param external Whether or not the emote is external
|
||||
*/
|
||||
void addEmoteForServer(Emote emote, Guild guild, Long count, boolean external);
|
||||
|
||||
/**
|
||||
* Calculates the key used for the Map containing the emote statistics.
|
||||
* @return The calculated key to be used in the Map
|
||||
*/
|
||||
Long getKey();
|
||||
|
||||
/**
|
||||
* Creates a {@link PersistingEmote} from the given parameters.
|
||||
* @param guild The {@link Guild} in which the {@link Emote} is used
|
||||
* @param emote The {@link Emote} to create a {@link PersistingEmote} from
|
||||
* @param external Whether or not the {@link Emote} is external
|
||||
* @return A created {@link PersistingEmote} instance from the {@link Emote}
|
||||
*/
|
||||
PersistingEmote createFromEmote(Guild guild, Emote emote, boolean external);
|
||||
|
||||
/**
|
||||
* Creates a {@link PersistingEmote} from the given parameters.
|
||||
* @param guild The {@link Guild} in which the {@link Emote} is used
|
||||
* @param emote The {@link Emote} to create a {@link PersistingEmote} from
|
||||
* @param count The amount of usages the {@link Emote} has been used
|
||||
* @param external Whether or not the {@link Emote} is external
|
||||
* @return A created {@link PersistingEmote} instance from the {@link Emote}
|
||||
*/
|
||||
PersistingEmote createFromEmote(Guild guild, Emote emote, Long count, boolean external);
|
||||
|
||||
/**
|
||||
* Acquires the lock which should be used when accessing the runtime storage
|
||||
*/
|
||||
void takeLock();
|
||||
|
||||
/**
|
||||
* Releases the lock which should be used then accessing the runtime storage
|
||||
*/
|
||||
void releaseLock();
|
||||
}
|
||||
|
||||
@@ -10,18 +10,111 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service responsible to provide operations on {@link TrackedEmote}
|
||||
*/
|
||||
public interface TrackedEmoteService {
|
||||
|
||||
/**
|
||||
* Adds the given list of {@link Emote}s to the runtime storage for the given {@link Guild}
|
||||
* @param emotes The list of {@link Emote}s to add to the runtime storage
|
||||
* @param guild The {@link Guild} in which the {@link Emote}s were used and where the usages should be added
|
||||
*/
|
||||
void addEmoteToRuntimeStorage(List<Emote> emotes, Guild guild);
|
||||
|
||||
/**
|
||||
* Adds the given {@link Emote} with the given amount to the runtime storage for the given {@link Guild}
|
||||
* @param emote The {@link Emote} to add to the runtime storage
|
||||
* @param guild The {@link Guild} in which the {@link Emote} was used and in which the usage should be added
|
||||
* @param count The amount of times which the {@link Emote} has been used and should be reflected in the runtime storage
|
||||
*/
|
||||
void addEmoteToRuntimeStorage(Emote emote, Guild guild, Long count);
|
||||
|
||||
/**
|
||||
* Takes the given map of server_ids with the list of {@link PersistingEmote} and stores the objects in the database
|
||||
* Non existing {@link TrackedEmote} for the server will be created. Depending on the feature mode external emotes will be created.
|
||||
* @param usagesToStore The map of server_ids to a List of {@link PersistingEmote} which should be stored in the database
|
||||
*/
|
||||
void storeEmoteStatistics(Map<Long, List<PersistingEmote>> usagesToStore);
|
||||
|
||||
/**
|
||||
* Creates a fake {@link TrackedEmote} from the given {@link Emote} and {@link Guild}. This {@link TrackedEmote}
|
||||
* is not persisted and has the fake value set to true
|
||||
* @param emote The {@link Emote} to be used for the fake {@link TrackedEmote}
|
||||
* @param guild The {@link Guild} to be used for the fake {@link TrackedEmote}
|
||||
* @return The fake {@link TrackedEmote} which was created
|
||||
*/
|
||||
TrackedEmote getFakeTrackedEmote(Emote emote, Guild guild);
|
||||
TrackedEmote getFakeTrackedEmote(Long id, Guild guild);
|
||||
|
||||
/**
|
||||
* Creates a fake {@link TrackedEmote} from the given emote ID and server ID. This {@link TrackedEmote}
|
||||
* is not persisted and has the fake value set to true
|
||||
* @param emoteId The ID of an {@link Emote}
|
||||
* @param guild The ID of an {@link dev.sheldan.abstracto.core.models.database.AServer}
|
||||
* @return The fake {@link TrackedEmote} which was created
|
||||
*/
|
||||
TrackedEmote getFakeTrackedEmote(Long emoteId, Guild guild);
|
||||
|
||||
/**
|
||||
* Checks the currently existing {@link Emote}s in the {@link Guild} with the currently {@link TrackedEmote} and synchronizes
|
||||
* the state. This means: unknown {@link Emote} are created as {@link TrackedEmote} and already existing {@link TrackedEmote}
|
||||
* which are not found in the {@link Guild} are marked as deleted.
|
||||
* @param guild The {@link Guild} to synchronize the {@link Emote} for
|
||||
* @return The {@link TrackedEmoteSynchronizationResult} which contains information about what changed (number of deletions and additions)
|
||||
*/
|
||||
TrackedEmoteSynchronizationResult synchronizeTrackedEmotes(Guild guild);
|
||||
|
||||
/**
|
||||
* Loads all the {@link TrackedEmote} for the given {@link Guild} for which tracking is enabled into a {@link TrackedEmoteOverview}
|
||||
* @param guild The {@link Guild} to retrieve the {@link TrackedEmote} for
|
||||
* @return The {@link TrackedEmoteOverview} containing the {@link TrackedEmote} which have tracking enabled
|
||||
*/
|
||||
TrackedEmoteOverview loadTrackedEmoteOverview(Guild guild);
|
||||
|
||||
/**
|
||||
* Loads all the {@link TrackedEmote} for the given {@link Guild}. If showTrackingDisabled is true, it will also
|
||||
* show {@link TrackedEmote} for which tracking has been disabled
|
||||
* @param guild The {@link Guild} to retrieve the {@link TrackedEmoteOverview} for
|
||||
* @param showTrackingDisabled Whether or not to include {@link TrackedEmote} for which tracking has been disabled
|
||||
* @return The {@link TrackedEmoteOverview} containing the retrieved {@link TrackedEmote} depending on the criteria
|
||||
*/
|
||||
TrackedEmoteOverview loadTrackedEmoteOverview(Guild guild, Boolean showTrackingDisabled);
|
||||
TrackedEmote createFakeTrackedEmote(Emote emote, Guild guild);
|
||||
TrackedEmote createFakeTrackedEmote(Emote emote, Guild guild, boolean external);
|
||||
|
||||
/**
|
||||
* Creates a {@link TrackedEmote} from the {@link Emote} based on a usage in {@link Guild}
|
||||
* This method detects if the {@link Emote} is external or not on its own.
|
||||
* @param emote The {@link Emote} to create a {@link TrackedEmote} for
|
||||
* @param guild The {@link Guild} for which the {@link TrackedEmote} should be created for
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Emote emote, Guild guild);
|
||||
|
||||
/**
|
||||
* Creates a {@link TrackedEmote} from the {@link Emote} based on a usage in {@link Guild}
|
||||
* @param emote The {@link Emote} to create a {@link TrackedEmote} for
|
||||
* @param guild The {@link Guild} in which the {@link TrackedEmote} should be created for
|
||||
* @param external Whether or not the {@link Emote} is part of the {@link Guild} or not
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external);
|
||||
|
||||
/**
|
||||
* Deletes the referenced {@link TrackedEmote} in the database
|
||||
* @param trackedEmote The {@link TrackedEmote} to delete
|
||||
*/
|
||||
void deleteTrackedEmote(TrackedEmote trackedEmote);
|
||||
|
||||
/**
|
||||
* Completely resets the emote statistics in {@link Guild}. This will purge all emote usages and delete all {@link TrackedEmote}
|
||||
* of this {@link Guild}
|
||||
* @param guild The {@link Guild} to reset the emote statistics for
|
||||
*/
|
||||
void resetEmoteStats(Guild guild);
|
||||
|
||||
/**
|
||||
* Disables emote tracking for *every* {@link TrackedEmote} within the {@link Guild} individually. Effectively disabling
|
||||
* emote tracking within the server.
|
||||
* @param guild The {@link Guild} to disable emote tracking for
|
||||
*/
|
||||
void disableEmoteTracking(Guild guild);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,58 @@ import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Service responsible to provide operations on {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote}
|
||||
*/
|
||||
public interface UsedEmoteService {
|
||||
/**
|
||||
* Retrieves the {@link EmoteStatsModel} for the {@link AServer} since {@link Instant}.
|
||||
* This {@link EmoteStatsModel} will contain all {@link TrackedEmote} from the server
|
||||
* @param server The {@link AServer} to retrieve the emote stats for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static {@link net.dv8tion.jda.api.entities.Emote}
|
||||
*/
|
||||
EmoteStatsModel getEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Retrieves the {@link EmoteStatsModel} for the {@link AServer} since {@link Instant}.
|
||||
* This {@link EmoteStatsModel} will contain only deleted {@link TrackedEmote} from the server
|
||||
* @param server The {@link AServer} to retrieve the emote stats for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static {@link net.dv8tion.jda.api.entities.Emote}
|
||||
*/
|
||||
EmoteStatsModel getDeletedEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Retrieves the {@link EmoteStatsModel} for the {@link AServer} since {@link Instant}.
|
||||
* This {@link EmoteStatsModel} will contain only external {@link TrackedEmote} from the server
|
||||
* @param server The {@link AServer} to retrieve the emote stats for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static {@link net.dv8tion.jda.api.entities.Emote}
|
||||
*/
|
||||
EmoteStatsModel getExternalEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Retrieves the {@link EmoteStatsModel} for the {@link AServer} since {@link Instant}.
|
||||
* This {@link EmoteStatsModel} will contain only active {@link TrackedEmote} from the server. These are emotes which are still present
|
||||
* the {@link net.dv8tion.jda.api.entities.Guild}
|
||||
* @param server The {@link AServer} to retrieve the emote stats for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static {@link net.dv8tion.jda.api.entities.Emote}
|
||||
*/
|
||||
EmoteStatsModel getActiveEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Removes all {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote} for the given {@link TrackedEmote} which are younger
|
||||
* than the given {@link Instant}
|
||||
* @param emote The {@link TrackedEmote} which should have its usages removed
|
||||
* @param since {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote} younger than this {@link Instant} shold be remoed. Only the date porition is considered.
|
||||
*/
|
||||
void purgeEmoteUsagesSince(TrackedEmote emote, Instant since);
|
||||
|
||||
/**
|
||||
* Removes *all* {@link dev.sheldan.abstracto.statistic.emotes.model.database.UsedEmote} for the given {@link TrackedEmote}.
|
||||
* @param emote The {@link TrackedEmote} which should have its usages removed
|
||||
*/
|
||||
void purgeEmoteUsages(TrackedEmote emote);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,195 @@
|
||||
package dev.sheldan.abstracto.statistic.emotes.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.statistic.emotes.exception.TrackedEmoteNotFoundException;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.PersistingEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emotes.model.database.embed.TrackedEmoteServer;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Service responsible for managing {@link TrackedEmote} instances in the database
|
||||
*/
|
||||
public interface TrackedEmoteManagementService {
|
||||
/**
|
||||
* Creates and persists a {@link TrackedEmote} for which tracking is enabled with the given individual parameters
|
||||
* @param emoteId The ID of the {@link Emote} to track
|
||||
* @param emoteName The name of the {@link Emote} to track
|
||||
* @param animated Whether or not the {@link Emote} to track is animated
|
||||
* @param server The {@link AServer} for which the {@link Emote} should be tracked
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Long emoteId, String emoteName, Boolean animated, AServer server);
|
||||
|
||||
/**
|
||||
* Creates and persists a {@link TrackedEmote} for which tracking is enabled based on the given {@link Emote} and {@link Guild}
|
||||
* @param emote The {@link Emote} to be used to create a {@link TrackedEmote}
|
||||
* @param guild The {@link Guild} for which the emote should be tracked for
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Emote emote, Guild guild);
|
||||
|
||||
/**
|
||||
* Creates and persist a {@link TrackedEmote} for which tracking is enabled based on the given {@link Emote} and {@link Guild}
|
||||
* @param emote The {@link Emote} to be used to create a {@link TrackedEmote}
|
||||
* @param guild The {@link Guild} for which the emote should be tracked for
|
||||
* @param external Whether or not the emote is external
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external);
|
||||
|
||||
/**
|
||||
* Creates and persis a {@link TrackedEmote} based ont he given parameters
|
||||
* @param emoteId The ID of an {@link Emote}
|
||||
* @param emoteName The name of an {@link Emote}
|
||||
* @param animated Whether or not the {@link Emote} is enabled
|
||||
* @param tracked Whether or not the {@link TrackedEmote} should have tracking enabled
|
||||
* @param server The {@link AServer} for which the {@link TrackedEmote} should be created
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createTrackedEmote(Long emoteId, String emoteName, Boolean animated, Boolean tracked, AServer server);
|
||||
TrackedEmote createExternalEmote(Long emoteId, String emoteName, String externalUrl, Boolean animated, AServer server);
|
||||
|
||||
/**
|
||||
* Creates an {@link TrackedEmote} based on the parameters which is external
|
||||
* @param emoteId The ID of an {@link Emote}
|
||||
* @param emoteName the name of an {@link Emote}
|
||||
* @param externalUrl The URL of the {@link Emote} which should be stored
|
||||
* @param animated Whether or not the {@link Emote} is external
|
||||
* @param server The {@link AServer} for which the {@link TrackedEmote} should be created
|
||||
* @param trackingEnabled Whether or not the {@link TrackedEmote} should have tracking enabled
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createExternalEmote(Long emoteId, String emoteName, String externalUrl, Boolean animated, AServer server, boolean trackingEnabled);
|
||||
|
||||
/**
|
||||
* Creates an {@link TrackedEmote} based on the parameters which is not being tracked
|
||||
* @param emoteId The ID of an {@link Emote}
|
||||
* @param emoteName The name of an {@link Emote}
|
||||
* @param animated Whether or not the {@link Emote} is animated
|
||||
* @param server The {@link AServer} for which the {@link TrackedEmote} should be created
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createNotTrackedEmote(Long emoteId, String emoteName, Boolean animated, AServer server);
|
||||
TrackedEmote createExternalEmote(PersistingEmote persistingEmote);
|
||||
TrackedEmote createExternalEmote(Emote emote, Guild guild);
|
||||
|
||||
/**
|
||||
* Creates an {@link TrackedEmote} based on the {@link PersistingEmote} which is being tracked
|
||||
* @param persistingEmote The {@link PersistingEmote} to create the {@link TrackedEmote} based of
|
||||
* @return The created {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createExternalTrackedEmote(PersistingEmote persistingEmote);
|
||||
|
||||
/**
|
||||
* Creates an external {@link TrackedEmote} based on the {@link Emote} and the {@link Guild}
|
||||
* @param emote The {@link Emote} to be used to create an external {@link TrackedEmote}
|
||||
* @param guild The {@link Guild} for which the emote should be tracked for
|
||||
* @return The create {@link TrackedEmote} instance in the database
|
||||
*/
|
||||
TrackedEmote createExternalTrackedEmote(Emote emote, Guild guild);
|
||||
|
||||
/**
|
||||
* Marks the {@link TrackedEmote} identified by serverId and emoteId as deleted
|
||||
* @param serverId The ID of the server to mark the {@link TrackedEmote} as deleted
|
||||
* @param emoteId The ID of the {@link Emote} to mark the {@link TrackedEmote} as deleted
|
||||
* @throws TrackedEmoteNotFoundException if no {@link TrackedEmote} with the given IDs can be found
|
||||
*/
|
||||
void markAsDeleted(Long serverId, Long emoteId);
|
||||
void markAsDeleted(TrackedEmote trackedemote);
|
||||
|
||||
/**
|
||||
* Marks the given {@link TrackedEmote} as deleted
|
||||
* @param trackedEmote The {@link TrackedEmote} which should be marked as deleted
|
||||
*/
|
||||
void markAsDeleted(TrackedEmote trackedEmote);
|
||||
|
||||
/**
|
||||
* Retrieves a {@link TrackedEmote} by the given emoteID and serverID
|
||||
* @param emoteId The ID of the {@link AServer} so search for
|
||||
* @param serverId The ID Of the {@link Emote} to search for
|
||||
* @return The found {@link TrackedEmote} instance if, one exists
|
||||
* @throws TrackedEmoteNotFoundException if no {@link TrackedEmote} with the given IDs can be found
|
||||
*/
|
||||
TrackedEmote loadByEmoteId(Long emoteId, Long serverId);
|
||||
|
||||
/**
|
||||
* Loads a {@link TrackedEmote} by the given {@link Emote}. The ID necessary for the server is the {@link Guild} from the emote.
|
||||
* The {@link Emote} must containing a {@link Guild} object, this is not guaranteed, but this implementation relies on it.
|
||||
* @param emote The {@link Emote} to find a {@link TrackedEmote} for
|
||||
* @return The {@link TrackedEmote} which was found
|
||||
* @throws TrackedEmoteNotFoundException if no {@link TrackedEmote} with the given IDs can be found
|
||||
*/
|
||||
TrackedEmote loadByEmote(Emote emote);
|
||||
|
||||
/**
|
||||
* Checks whether or not a {@link TrackedEmote} with the given emote ID and server ID exists
|
||||
* @param emoteId The ID of an {@link Emote} to check
|
||||
* @param serverId the ID of an {@link AServer} to check
|
||||
* @return Whether or not a {@link TrackedEmote} with the given IDs exists
|
||||
*/
|
||||
boolean trackedEmoteExists(Long emoteId, Long serverId);
|
||||
TrackedEmote loadByTrackedEmoteServer(TrackedEmoteServer trackedEmoteServer);
|
||||
|
||||
/**
|
||||
* Loads a {@link TrackedEmote} based on its composite keys represented by a {@link ServerSpecificId}
|
||||
* @param trackedEmoteServer The {@link ServerSpecificId} to retrieve a {@link TrackedEmote} from
|
||||
* @return The found {@link TrackedEmote} based on the given parameters
|
||||
* @throws TrackedEmoteNotFoundException if no {@link TrackedEmote} with the given {@link ServerSpecificId} was found
|
||||
*/
|
||||
TrackedEmote loadByTrackedEmoteServer(ServerSpecificId trackedEmoteServer);
|
||||
|
||||
/**
|
||||
* Searches for a {@link TrackedEmote} by the given emoteId and serverId and returns an {@link Optional} containing the value, if any.
|
||||
* @param emoteId The ID of the {@link Emote} to search for
|
||||
* @param serverId The ID of the {@link AServer} to search for
|
||||
* @return An {@link Optional} containing a {@link TrackedEmote} if it exists, empty otherwise
|
||||
*/
|
||||
Optional<TrackedEmote> loadByEmoteIdOptional(Long emoteId, Long serverId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link TrackedEmote} for a {@link AServer}, which are not yet deleted and not external
|
||||
* @param server The {@link AServer} to retrieve the active {@link TrackedEmote} for
|
||||
* @return A list of {@link TrackedEmote} which are currently considered active from the {@link AServer}
|
||||
*/
|
||||
List<TrackedEmote> getAllActiveTrackedEmoteForServer(AServer server);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link TrackedEmote} for an ID of a {@link AServer}, which are not yet deleted and not external
|
||||
* @param serverId The ID of an {@link AServer} ro retrieve the active {@link TrackedEmote} for
|
||||
* @return A list of {@link TrackedEmote} which are currently considered active from the {@link AServer} with the ID
|
||||
*/
|
||||
List<TrackedEmote> getAllActiveTrackedEmoteForServer(Long serverId);
|
||||
|
||||
/**
|
||||
* Retrieves *all* tracking enabled {@link TrackedEmote} for an ID of a {@link AServer}, with the option to also retrieve the ones for which tracking is disable
|
||||
* @param serverId The ID of an {@link AServer} to retrieve the {@link TrackedEmote} for
|
||||
* @param showTrackingDisabledEmotes Whether or not tracking disabled {@link TrackedEmote} should be retrieved as well
|
||||
* @return A list of {@link TrackedEmote} from an {@link AServer} with the given ID
|
||||
*/
|
||||
List<TrackedEmote> getTrackedEmoteForServer(Long serverId, Boolean showTrackingDisabledEmotes);
|
||||
|
||||
/**
|
||||
* Changes the name of the given {@link TrackedEmote} to a new value
|
||||
* @param emote The {@link TrackedEmote} to change the name of
|
||||
* @param name The new name to change to
|
||||
*/
|
||||
void changeName(TrackedEmote emote, String name);
|
||||
|
||||
/**
|
||||
* Disables the tracking of a {@link TrackedEmote}
|
||||
* @param emote The {@link TrackedEmote} to disable the tracking of
|
||||
*/
|
||||
void disableTrackedEmote(TrackedEmote emote);
|
||||
|
||||
/**
|
||||
* Enables the tracking of a {@link TrackedEmote}
|
||||
* @param emote The {@link TrackedEmote} to enable the tracking of
|
||||
*/
|
||||
void enableTrackedEmote(TrackedEmote emote);
|
||||
|
||||
/**
|
||||
* Deletes the given {@link TrackedEmote}
|
||||
* @param emote The {@link TrackedEmote} to delete
|
||||
*/
|
||||
void deleteTrackedEmote(TrackedEmote emote);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,70 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Service responsible for creating/updating/deleting {@link UsedEmote} instances in the database
|
||||
*/
|
||||
public interface UsedEmoteManagementService {
|
||||
/**
|
||||
* Loads an {@link Optional} containing a {@link UsedEmote} for the particular {@link TrackedEmote} for the current day.
|
||||
* The {@link Optional} is empty, if none exists.
|
||||
* @param trackedEmote The {@link TrackedEmote} to search a {@link UsedEmote} for today
|
||||
* @return An {@link Optional} containing a {@link UsedEmote}, if it exists for the current day
|
||||
*/
|
||||
Optional<UsedEmote> loadUsedEmoteForTrackedEmoteToday(TrackedEmote trackedEmote);
|
||||
|
||||
/**
|
||||
* Creates and persists and instance of {@link UsedEmote} from the given {@link TrackedEmote}, with the defined count and the current date.
|
||||
* @param trackedEmote The {@link TrackedEmote} for which to create a {@link UsedEmote} for
|
||||
* @param count The amount of usages for the {@link UsedEmote}
|
||||
* @return The created {@link UsedEmote} instance int he database
|
||||
*/
|
||||
UsedEmote createEmoteUsageForToday(TrackedEmote trackedEmote, Long count);
|
||||
|
||||
/**
|
||||
* Loads {@link UsedEmote} for the {@link AServer} which are newer than the given {@link Instant}
|
||||
* @param server The {@link AServer} to retrieve the {@link UsedEmote} for
|
||||
* @param since The {@link Instant} since when the emote stats should be retrieved. Only the date portion is considered.
|
||||
* @return A list of {@link UsedEmote} from the {@link AServer} newer than the given {@link Instant}
|
||||
*/
|
||||
List<UsedEmote> loadEmoteUsagesForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Load {@link EmoteStatsResult} from the {@link AServer} for all {@link TrackedEmote} which are newer than {@link Instant}
|
||||
* @param server The {@link AServer} to retrieve the emote statistics for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return A list of {@link EmoteStatsResult} from the {@link AServer} newer than the given {@link Instant} for all {@link TrackedEmote}
|
||||
*/
|
||||
List<EmoteStatsResult> loadAllEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Load {@link EmoteStatsResult} from the {@link AServer} for {@link TrackedEmote} which were deleted and newer than {@link Instant}
|
||||
* @param server The {@link AServer} to retrieve the emote statistics for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return A list of {@link EmoteStatsResult} from the {@link AServer} newer than the given {@link Instant} for all deleted {@link TrackedEmote}
|
||||
*/
|
||||
List<EmoteStatsResult> loadDeletedEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Load {@link EmoteStatsResult} from the {@link AServer} for {@link TrackedEmote} which are external and newer than {@link Instant}
|
||||
* @param server The {@link AServer} to retrieve the emote statistic for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return A list of {@link EmoteStatsResult} from the {@link AServer} newer than the given {@link Instant} for all external {@link TrackedEmote}
|
||||
*/
|
||||
List<EmoteStatsResult> loadExternalEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Load {@link EmoteStatsResult} from the {@link AServer} for {@link TrackedEmote} which are active and newer than {@link Instant}
|
||||
* @param server The {@link AServer} to retrieve the emote statistic for
|
||||
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered.
|
||||
* @return A list of {@link EmoteStatsResult} from the {@link AServer} newer than the given {@link Instant} for all active {@link TrackedEmote}
|
||||
*/
|
||||
List<EmoteStatsResult> loadActiveEmoteStatsForServerSince(AServer server, Instant since);
|
||||
|
||||
/**
|
||||
* Deletes all emote usages for the {@link TrackedEmote} which are younger than the given {@link Instant}
|
||||
* @param emote The {@link TrackedEmote} to remove the usages for
|
||||
* @param since All emote stats which are newer than this {@link Instant} will be deleted
|
||||
*/
|
||||
void purgeEmoteUsagesSince(TrackedEmote emote, Instant since);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user