sort sniped messages
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 42s

This commit is contained in:
Lee 2024-07-02 00:54:55 +01:00
parent 37c69597be
commit 1a69bce9dd
5 changed files with 8 additions and 6 deletions

@ -6,12 +6,10 @@ import cc.fascinated.bat.service.EventService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.mongock.runner.springboot.EnableMongock;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@ -57,6 +57,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
*/
public static SnipedMessage getDeletedMessage(BatGuild guild, String channelId) {
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
messages.sort(Comparator.comparing(SnipedMessage::getDeletedDate));
for (SnipedMessage message : messages) {
if (message.getDeletedDate() != null // Check if the message was deleted
&& message.getMessage().getChannel().getId().equals(channelId)) {

@ -18,7 +18,6 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.Command;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
@ -48,8 +47,7 @@ public class CommandService extends ListenerAdapter {
private final UserService userService;
@Autowired
public CommandService(@NonNull ApplicationContext context, @NonNull GuildService guildService, @NonNull UserService userService) {
context.getBean(Config.class);
public CommandService(@NonNull GuildService guildService, @NonNull UserService userService) {
this.guildService = guildService;
this.userService = userService;
DiscordService.JDA.addEventListener(this);

@ -2,7 +2,9 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.common.NumberFormatter;
import cc.fascinated.bat.common.TimerUtils;
import cc.fascinated.bat.config.Config;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
@ -11,6 +13,7 @@ import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.util.EnumSet;
@ -38,8 +41,10 @@ public class DiscordService {
@Autowired
public DiscordService(
@NonNull ApplicationContext context,
@Value("${discord.token}") String token
) throws Exception {
context.getBean(Config.class); // Ensure the config is loaded
log.info("Starting Discord bot...");
JDA = JDABuilder.create(token, EnumSet.of(
GatewayIntent.GUILD_MESSAGES,

@ -50,7 +50,7 @@ public class EventService extends ListenerAdapter {
DiscordService.JDA.addEventListener(this);
context.getBeansOfType(EventListener.class).values().forEach(this::registerListeners);
log.info("Registered {} listeners.", LISTENERS.size());
log.info("Registered {} event listeners.", LISTENERS.size());
}
/**