diff --git a/src/main/java/cc/fascinated/bat/BatApplication.java b/src/main/java/cc/fascinated/bat/BatApplication.java index d20c67f..09570d2 100644 --- a/src/main/java/cc/fascinated/bat/BatApplication.java +++ b/src/main/java/cc/fascinated/bat/BatApplication.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java index 28cd1f9..9606b9f 100644 --- a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java +++ b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java @@ -57,6 +57,7 @@ public class MessageSnipeFeature extends Feature implements EventListener { */ public static SnipedMessage getDeletedMessage(BatGuild guild, String channelId) { List 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)) { diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 739adba..a7f4f46 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -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); diff --git a/src/main/java/cc/fascinated/bat/service/DiscordService.java b/src/main/java/cc/fascinated/bat/service/DiscordService.java index e5a71dc..bfa0c00 100644 --- a/src/main/java/cc/fascinated/bat/service/DiscordService.java +++ b/src/main/java/cc/fascinated/bat/service/DiscordService.java @@ -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, diff --git a/src/main/java/cc/fascinated/bat/service/EventService.java b/src/main/java/cc/fascinated/bat/service/EventService.java index ef7e867..372a121 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -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()); } /**