mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-07-05 12:22:26 +00:00
[AB-8] upgrading to new JDA alpha version 19
cleaning up imports
This commit is contained in:
@@ -4,23 +4,23 @@ import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
* Container class for containing both an {@link CustomEmoji} 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.emote.command.TrackEmote} and is used as a convenience parameter, in which there
|
||||
* might both a {@link Emote} and a {@link TrackedEmote} as parameter
|
||||
* might both a {@link CustomEmoji} 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
|
||||
* If an {@link CustomEmoji} has been used as parameter, this will have the appropriate value
|
||||
*/
|
||||
private Emote emote;
|
||||
private CustomEmoji emote;
|
||||
/**
|
||||
* If a {@link Long} or {@link Emote} has been supplied as the parameter, this will contain a faked instance of the respective values
|
||||
* If a {@link Long} or {@link CustomEmoji} has been supplied as the parameter, this will contain a faked instance of the respective values
|
||||
*/
|
||||
private TrackedEmote trackedEmote;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import dev.sheldan.abstracto.core.command.handler.provided.EmoteParameterHandler
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* At first it will see if there are any {@link CustomEmoji} 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
|
||||
@@ -59,8 +59,8 @@ public class TrackedEmoteParameterHandler implements CommandParameterHandler {
|
||||
@Override
|
||||
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
|
||||
Parameter cloned = commandService.cloneParameter(param);
|
||||
cloned.setType(Emote.class);
|
||||
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, cloned, context, command);
|
||||
cloned.setType(CustomEmoji.class);
|
||||
CustomEmoji emote = (CustomEmoji) emoteParameterHandler.handle(input, iterators, cloned, context, command);
|
||||
if(emote != null) {
|
||||
return trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild());
|
||||
} else {
|
||||
|
||||
@@ -11,16 +11,16 @@ import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.statistic.emote.command.parameter.TrackEmoteParameter;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
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 EmoteParameterHandler} and use the returned {@link CustomEmoji} 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.emote.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
|
||||
* and only make the {@link CustomEmoji} available in the result, if it was passed as such. This handler has a slightly higher priority
|
||||
* than medium.
|
||||
*/
|
||||
@Component
|
||||
@@ -47,8 +47,8 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* This tries to parse the input and extract an {@link CustomEmoji} 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 CustomEmoji} 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
|
||||
@@ -56,15 +56,15 @@ public class TrackedEmoteParameterParameterHandler implements CommandParameterHa
|
||||
* @param param The {@link Class} which this type should handle
|
||||
* @param context The {@link Message} which caused the command to be executed
|
||||
* @param command
|
||||
* @return An instance of {@link TrackEmoteParameter} which contains the available instances. This is an {@link Emote} in case it was
|
||||
* @return An instance of {@link TrackEmoteParameter} which contains the available instances. This is an {@link CustomEmoji} in case it was
|
||||
* used directly. In every successful case, it will contain a faked {@link TrackedEmote}.
|
||||
*/
|
||||
@Override
|
||||
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
|
||||
TrackEmoteParameter parameter = TrackEmoteParameter.builder().build();
|
||||
Parameter cloned = commandService.cloneParameter(param);
|
||||
cloned.setType(Emote.class);
|
||||
Emote emote = (Emote) emoteParameterHandler.handle(input, iterators, cloned, context, command);
|
||||
cloned.setType(CustomEmoji.class);
|
||||
CustomEmoji emote = (CustomEmoji) emoteParameterHandler.handle(input, iterators, cloned, context, command);
|
||||
if(emote != null) {
|
||||
parameter.setEmote(emote);
|
||||
parameter.setTrackedEmote(trackedEmoteService.getFakeTrackedEmote(emote, context.getGuild()));
|
||||
|
||||
@@ -6,8 +6,8 @@ import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResult;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.EmoteStatsResultDisplay;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -15,7 +15,7 @@ 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
|
||||
* This for example loads the relevant {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} to be used within the model and also splits it up
|
||||
* into static and animated emotes
|
||||
*/
|
||||
@Component
|
||||
@@ -53,10 +53,10 @@ public class EmoteStatsConverter {
|
||||
|
||||
private EmoteStatsResultDisplay convertEmoteStatsResult(Guild relevantGuild, EmoteStatsResult emoteStatsResult) {
|
||||
TrackedEmote trackedEmote = trackedEmoteManagementService.loadByEmoteId(emoteStatsResult.getEmoteId(), emoteStatsResult.getServerId());
|
||||
Emote loadedEmote = null;
|
||||
CustomEmoji loadedEmote = null;
|
||||
// if the emote should still exist, we try to load it
|
||||
if(!trackedEmote.getExternal() && !trackedEmote.getDeleted()) {
|
||||
loadedEmote = relevantGuild.getEmoteById(trackedEmote.getTrackedEmoteId().getId());
|
||||
loadedEmote = relevantGuild.getEmojiById(trackedEmote.getTrackedEmoteId().getId());
|
||||
}
|
||||
return EmoteStatsResultDisplay
|
||||
.builder()
|
||||
|
||||
@@ -9,7 +9,6 @@ import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
|
||||
import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emote.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;
|
||||
|
||||
@@ -17,7 +16,7 @@ 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
|
||||
* This listener listens for created {@link net.dv8tion.jda.api.entities.emoji.RichCustomEmoji} in a {@link net.dv8tion.jda.api.entities.Guild} and creates appropriate
|
||||
* {@link dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote}, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
|
||||
* feature mode as well.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,6 @@ import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
|
||||
import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingMode;
|
||||
import dev.sheldan.abstracto.statistic.emote.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;
|
||||
|
||||
@@ -17,7 +16,7 @@ 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 marks respective
|
||||
* This listener listens for deleted {@link net.dv8tion.jda.api.entities.emoji.CustomEmoji} in a {@link net.dv8tion.jda.api.entities.Guild} and marks respective
|
||||
* {@link dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote} as deleted, if the EMOTE_TRACKING feature is enabled and the AUTO_TRACK
|
||||
* feature mode as well.
|
||||
*/
|
||||
|
||||
@@ -7,8 +7,8 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -40,11 +40,11 @@ public class EmoteTrackingListener implements AsyncMessageReceivedListener {
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Map<Long, List<Emote>> collect = message
|
||||
Map<Long, List<CustomEmoji>> collect = message
|
||||
.getMentions()
|
||||
.getEmotesBag()
|
||||
.getCustomEmojisBag()
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(Emote::getIdLong));
|
||||
.collect(Collectors.groupingBy(CustomEmoji::getIdLong));
|
||||
collect.values().forEach(groupedEmotes ->
|
||||
trackedEmoteService.addEmoteToRuntimeStorage(groupedEmotes.get(0), guildService.getGuildById(model.getServerId()), (long) groupedEmotes.size())
|
||||
);
|
||||
|
||||
@@ -18,8 +18,9 @@ import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.management.TrackedEmoteManagementService;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.management.UsedEmoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -87,7 +88,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEmoteToRuntimeStorage(Emote emote, Guild guild, Long count) {
|
||||
public void addEmoteToRuntimeStorage(CustomEmoji emote, Guild guild, Long count) {
|
||||
addEmoteToRuntimeStorage(cacheEntityService.getCachedEmoteFromEmote(emote, guild), guild, count);
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote getFakeTrackedEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote getFakeTrackedEmote(CustomEmoji emote, Guild guild) {
|
||||
return getFakeTrackedEmote(emote.getIdLong(), guild);
|
||||
}
|
||||
|
||||
@@ -158,10 +159,10 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
public TrackedEmoteSynchronizationResult synchronizeTrackedEmotes(Guild guild) {
|
||||
List<TrackedEmote> activeTrackedEmotes = trackedEmoteManagementService.getAllActiveTrackedEmoteForServer(guild.getIdLong());
|
||||
Long addedEmotes = 0L;
|
||||
List<Emote> allExistingEmotes = guild.getEmotes();
|
||||
List<RichCustomEmoji> allExistingEmotes = guild.getEmojis();
|
||||
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) {
|
||||
for (RichCustomEmoji emote : allExistingEmotes) {
|
||||
// find the emote in the list of known TrackedEmote
|
||||
Optional<TrackedEmote> trackedEmoteOptional = activeTrackedEmotes
|
||||
.stream()
|
||||
@@ -206,13 +207,13 @@ public class TrackedEmoteServiceBean implements TrackedEmoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild) {
|
||||
boolean external = !emoteService.emoteIsFromGuild(emote, guild);
|
||||
return createTrackedEmote(emote, guild, external);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
|
||||
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild, boolean external) {
|
||||
return trackedEmoteManagementService.createTrackedEmote(emote, guild, external);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ import dev.sheldan.abstracto.statistic.emote.model.PersistingEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.database.TrackedEmote;
|
||||
import dev.sheldan.abstracto.statistic.emote.repository.TrackedEmoteRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -33,13 +34,13 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild.getIdLong());
|
||||
return createTrackedEmote(emote.getIdLong(), emote.getName(), emote.isAnimated(), true, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote) {
|
||||
public TrackedEmote createTrackedEmote(RichCustomEmoji emote) {
|
||||
return createTrackedEmote(emote, emote.getGuild());
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createTrackedEmote(Emote emote, Guild guild, boolean external) {
|
||||
public TrackedEmote createTrackedEmote(CustomEmoji emote, Guild guild, boolean external) {
|
||||
if(external) {
|
||||
return createExternalTrackedEmote(emote, guild);
|
||||
} else {
|
||||
@@ -103,7 +104,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote createExternalTrackedEmote(Emote emote, Guild guild) {
|
||||
public TrackedEmote createExternalTrackedEmote(CustomEmoji emote, Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild.getIdLong());
|
||||
return createExternalEmote(emote.getIdLong(), emote.getName(), emote.getImageUrl(), emote.isAnimated(), server, true);
|
||||
}
|
||||
@@ -115,7 +116,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(Emote emote) {
|
||||
public void markAsDeleted(RichCustomEmoji emote) {
|
||||
markAsDeleted(emote.getGuild().getIdLong(), emote.getIdLong());
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ public class TrackedEmoteManagementServiceBean implements TrackedEmoteManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEmote loadByEmote(Emote emote) {
|
||||
public TrackedEmote loadByEmote(RichCustomEmoji emote) {
|
||||
return loadByEmoteId(emote.getIdLong(), emote.getGuild().getIdLong());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user