[AB-xxx] adding ability to track emotes used in reactions

adding ability to have confirmations for slash commands
This commit is contained in:
Sheldan
2025-01-27 01:31:56 +01:00
parent 2c3b16879e
commit ed42940e29
66 changed files with 1630 additions and 266 deletions

View File

@@ -0,0 +1,6 @@
package dev.sheldan.abstracto.statistic.config;
public class StatisticSlashCommandNames {
public static final String STATISTIC = "statistics";
public static final String STATISTIC_INTERNAL = "statisticsinteral";
}

View File

@@ -29,6 +29,9 @@ public class EmoteTrackingFeatureConfig implements FeatureConfig {
*/
@Override
public List<FeatureMode> getAvailableModes() {
return Arrays.asList(EmoteTrackingMode.EXTERNAL_EMOTES, EmoteTrackingMode.AUTO_TRACK, EmoteTrackingMode.AUTO_TRACK_EXTERNAL);
return Arrays.asList(EmoteTrackingMode.EXTERNAL_EMOTES,
EmoteTrackingMode.AUTO_TRACK,
EmoteTrackingMode.AUTO_TRACK_EXTERNAL,
EmoteTrackingMode.TRACK_REACTIONS);
}
}

View File

@@ -9,10 +9,14 @@ import lombok.Getter;
* 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
* TRACK_REACTIONS: if reactions are counted
*/
@Getter
public enum EmoteTrackingMode implements FeatureMode {
AUTO_TRACK("emoteAutoTrack"), EXTERNAL_EMOTES("externalEmotes"), AUTO_TRACK_EXTERNAL("autoTrackExternal");
AUTO_TRACK("emoteAutoTrack"),
EXTERNAL_EMOTES("externalEmotes"),
AUTO_TRACK_EXTERNAL("autoTrackExternal"),
TRACK_REACTIONS("trackReactions");
private final String key;

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.statistic.emote.model;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -33,6 +34,7 @@ public class PersistingEmote {
* Only if the emote is external: the URL where the source image of the emote is stored on Discord servers
*/
private String externalUrl;
private UsedEmoteType usedEmoteType;
/**
* The amount of times the emote has been used.
*/

View File

@@ -47,4 +47,5 @@ public class UsedEmote {
@Column(name = "updated", insertable = false, updatable = false)
private Instant updated;
}

View File

@@ -0,0 +1,6 @@
package dev.sheldan.abstracto.statistic.emote.model.database;
public enum UsedEmoteType {
MESSAGE,
REACTION;
}

View File

@@ -1,5 +1,8 @@
package dev.sheldan.abstracto.statistic.emote.model.database.embed;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.*;
import jakarta.persistence.Column;
@@ -36,4 +39,8 @@ public class UsedEmoteDay implements Serializable {
*/
@Column(name = "use_date")
private Instant useDate;
@Enumerated(EnumType.STRING)
@Column(name = "type")
private UsedEmoteType type;
}

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.statistic.emote.service;
import dev.sheldan.abstracto.core.models.cache.CachedEmote;
import dev.sheldan.abstracto.statistic.emote.model.PersistingEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import net.dv8tion.jda.api.entities.Guild;
import java.util.List;
@@ -18,24 +19,16 @@ public interface TrackedEmoteRuntimeService {
*/
Map<Long, Map<Long, List<PersistingEmote>>> getRuntimeConfig();
/**
* Adds the given {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} used in the {@link Guild} to the runtime storage.
* The necessary lock will be acquired by this method.
* @param emote The {@link CachedEmote} to add to the runtime storage
* @param guild The {@link Guild} in which the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} is used
* @param external Whether or not the emote is external
*/
void addEmoteForServer(CachedEmote emote, Guild guild, boolean external);
/**
* Adds the given {@link CachedEmote} used in the {@link Guild} to the runtime storage.
* The necessary lock will be acquired by this method.
* @param emote The {@link CachedEmote} to add to the runtime storage
* @param guild The {@link Guild} in which the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} is used
* @param count The amount of usages which should be added
* @param external Whether or not the emote is external
* @param external Whether the emote is external
* @param usedEmoteType The type of the emote
*/
void addEmoteForServer(CachedEmote emote, Guild guild, Long count, boolean external);
void addEmoteForServer(CachedEmote emote, Guild guild, Long count, boolean external, UsedEmoteType usedEmoteType);
/**
* Calculates the key used for the Map containing the emote statistics.
@@ -50,7 +43,7 @@ public interface TrackedEmoteRuntimeService {
* @param external Whether or not the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} is external
* @return A created {@link PersistingEmote} instance from the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji}
*/
PersistingEmote createFromEmote(Guild guild, CachedEmote emote, boolean external);
PersistingEmote createFromEmote(Guild guild, CachedEmote emote, boolean external, UsedEmoteType type);
/**
* Creates a {@link PersistingEmote} from the given parameters.
@@ -60,7 +53,7 @@ public interface TrackedEmoteRuntimeService {
* @param external Whether or not the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} is external
* @return A created {@link PersistingEmote} instance from the {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji}
*/
PersistingEmote createFromEmote(Guild guild, CachedEmote emote, Long count, boolean external);
PersistingEmote createFromEmote(Guild guild, CachedEmote emote, Long count, boolean external, UsedEmoteType usedEmoteType);
/**
* Acquires the lock which should be used when accessing the runtime storage

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.statistic.emote.model.PersistingEmote;
import dev.sheldan.abstracto.statistic.emote.model.TrackedEmoteOverview;
import dev.sheldan.abstracto.statistic.emote.model.TrackedEmoteSynchronizationResult;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
@@ -21,23 +22,25 @@ public interface TrackedEmoteService {
* @param emotes The list of {@link CustomEmoji}s to add to the runtime storage
* @param guild The {@link Guild} in which the {@link CustomEmoji}s were used and where the usages should be added
*/
void addEmoteToRuntimeStorage(List<CachedEmote> emotes, Guild guild);
void addEmoteToRuntimeStorage(List<CachedEmote> emotes, Guild guild, UsedEmoteType usedEmoteType);
/**
* Adds the given {@link CustomEmoji} with the given amount to the runtime storage for the given {@link Guild}
* @param emote The {@link CachedEmote} to add to the runtime storage
* @param guild The {@link Guild} in which the {@link CustomEmoji} was used and in which the usage should be added
* @param count The amount of times which the {@link CustomEmoji} has been used and should be reflected in the runtime storage
* @param type The type of interaction the emote came from
*/
void addEmoteToRuntimeStorage(CachedEmote emote, Guild guild, Long count);
void addEmoteToRuntimeStorage(CachedEmote emote, Guild guild, Long count, UsedEmoteType type);
/**
* Adds the given {@link CustomEmoji} with the given amount to the runtime storage for the given {@link Guild}
* @param emote The {@link CustomEmoji} to add to the runtime storage
* @param guild The {@link Guild} in which the {@link CustomEmoji} was used and in which the usage should be added
* @param count The amount of times which the {@link CustomEmoji} has been used and should be reflected in the runtime storage
* @param type The type of interaction the emote came from
*/
void addEmoteToRuntimeStorage(CustomEmoji emote, Guild guild, Long count);
void addEmoteToRuntimeStorage(CustomEmoji emote, Guild guild, Long count, UsedEmoteType type);
/**
* Takes the given map of server_ids with the list of {@link PersistingEmote} and stores the objects in the database

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsModel;
import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResultDisplay;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import java.time.Instant;
/**
@@ -25,29 +26,32 @@ public interface UsedEmoteService {
* 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.
* @param usedEmoteType The type of interaction the emote was from
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static emote
*/
EmoteStatsModel getDeletedEmoteStatsForServerSince(AServer server, Instant since);
EmoteStatsModel getDeletedEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType usedEmoteType);
/**
* 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.
* @param usedEmoteType The type of interaction the emote was used in
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static emote
*/
EmoteStatsModel getExternalEmoteStatsForServerSince(AServer server, Instant since);
EmoteStatsModel getExternalEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType usedEmoteType);
/**
* 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.
* @param since Emote stats should be younger than this {@link Instant}. Only the date portion is considered
* @param usedEmoteType The type of emote the interaction is coming from
* @return An {@link EmoteStatsModel} containing the statistics split by animated and static emote
*/
EmoteStatsModel getActiveEmoteStatsForServerSince(AServer server, Instant since);
EmoteStatsResultDisplay getEmoteStatForEmote(TrackedEmote trackedEmote, Instant since);
EmoteStatsModel getActiveEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType usedEmoteType);
EmoteStatsResultDisplay getEmoteStatForEmote(TrackedEmote trackedEmote, Instant since, UsedEmoteType usedEmoteType);
/**
* Removes all {@link dev.sheldan.abstracto.statistic.emote.model.database.UsedEmote} for the given {@link TrackedEmote} which are younger

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResult;
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmote;
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
@@ -17,26 +18,28 @@ 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
* @param usedEmoteType The type of interaction this emote was used in
* @return An {@link Optional} containing a {@link UsedEmote}, if it exists for the current day
*/
Optional<UsedEmote> loadUsedEmoteForTrackedEmoteToday(TrackedEmote trackedEmote);
Optional<UsedEmote> loadUsedEmoteForTrackedEmoteToday(TrackedEmote trackedEmote, UsedEmoteType usedEmoteType);
/**
* 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
* @param type The type of emote
* @return The created {@link UsedEmote} instance in the database
*/
UsedEmote createEmoteUsageForToday(TrackedEmote trackedEmote, Long count);
UsedEmote createEmoteUsageForToday(TrackedEmote trackedEmote, Long count, UsedEmoteType type);
/**
* Creates and persists and instance of {@link UsedEmote} from the given {@link TrackedEmote}, with the defined count and the given date.
* @param trackedEmote The {@link TrackedEmote} for which to create a {@link UsedEmote} for
* @param count The amount of usages for the {@link UsedEmote}
* @param instant The date to create the {@link UsedEmote emoteUsage} for
* @return The created {@link UsedEmote} instance int he database
* @return The created {@link UsedEmote} instance in the database
*/
UsedEmote createEmoteUsageFor(TrackedEmote trackedEmote, Long count, Instant instant);
UsedEmote createEmoteUsageFor(TrackedEmote trackedEmote, Long count, Instant instant, UsedEmoteType type);
/**
* Loads {@link UsedEmote} for the {@link AServer} which are newer than the given {@link Instant}
@@ -58,26 +61,29 @@ public interface UsedEmoteManagementService {
* 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.
* @param usedEmoteType The type of interaction the emote was used in
* @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);
List<EmoteStatsResult> loadDeletedEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType usedEmoteType);
/**
* 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.
* @param type The type of interaction the emote was used in
* @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);
List<EmoteStatsResult> loadExternalEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType type);
/**
* 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.
* @param type The type of emote that should be loaded
* @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);
EmoteStatsResult loadEmoteStatForEmote(TrackedEmote trackedEmote, Instant since);
List<EmoteStatsResult> loadActiveEmoteStatsForServerSince(AServer server, Instant since, UsedEmoteType type);
EmoteStatsResult loadEmoteStatForEmote(TrackedEmote trackedEmote, Instant since, UsedEmoteType usedEmoteType);
/**
* Deletes all emote usages for the {@link TrackedEmote} which are younger than the given {@link Instant}