sort sniped messages
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 42s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 42s
This commit is contained in:
parent
37c69597be
commit
1a69bce9dd
@ -6,12 +6,10 @@ import cc.fascinated.bat.service.EventService;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import io.mongock.runner.springboot.EnableMongock;
|
import io.mongock.runner.springboot.EnableMongock;
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
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) {
|
public static SnipedMessage getDeletedMessage(BatGuild guild, String channelId) {
|
||||||
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
|
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
|
||||||
|
messages.sort(Comparator.comparing(SnipedMessage::getDeletedDate));
|
||||||
for (SnipedMessage message : messages) {
|
for (SnipedMessage message : messages) {
|
||||||
if (message.getDeletedDate() != null // Check if the message was deleted
|
if (message.getDeletedDate() != null // Check if the message was deleted
|
||||||
&& message.getMessage().getChannel().getId().equals(channelId)) {
|
&& 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 net.dv8tion.jda.api.interactions.commands.Command;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -48,8 +47,7 @@ public class CommandService extends ListenerAdapter {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CommandService(@NonNull ApplicationContext context, @NonNull GuildService guildService, @NonNull UserService userService) {
|
public CommandService(@NonNull GuildService guildService, @NonNull UserService userService) {
|
||||||
context.getBean(Config.class);
|
|
||||||
this.guildService = guildService;
|
this.guildService = guildService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
DiscordService.JDA.addEventListener(this);
|
DiscordService.JDA.addEventListener(this);
|
||||||
|
@ -2,7 +2,9 @@ package cc.fascinated.bat.service;
|
|||||||
|
|
||||||
import cc.fascinated.bat.common.NumberFormatter;
|
import cc.fascinated.bat.common.NumberFormatter;
|
||||||
import cc.fascinated.bat.common.TimerUtils;
|
import cc.fascinated.bat.common.TimerUtils;
|
||||||
|
import cc.fascinated.bat.config.Config;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
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 net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@ -38,8 +41,10 @@ public class DiscordService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DiscordService(
|
public DiscordService(
|
||||||
|
@NonNull ApplicationContext context,
|
||||||
@Value("${discord.token}") String token
|
@Value("${discord.token}") String token
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
|
context.getBean(Config.class); // Ensure the config is loaded
|
||||||
log.info("Starting Discord bot...");
|
log.info("Starting Discord bot...");
|
||||||
JDA = JDABuilder.create(token, EnumSet.of(
|
JDA = JDABuilder.create(token, EnumSet.of(
|
||||||
GatewayIntent.GUILD_MESSAGES,
|
GatewayIntent.GUILD_MESSAGES,
|
||||||
|
@ -50,7 +50,7 @@ public class EventService extends ListenerAdapter {
|
|||||||
DiscordService.JDA.addEventListener(this);
|
DiscordService.JDA.addEventListener(this);
|
||||||
|
|
||||||
context.getBeansOfType(EventListener.class).values().forEach(this::registerListeners);
|
context.getBeansOfType(EventListener.class).values().forEach(this::registerListeners);
|
||||||
log.info("Registered {} listeners.", LISTENERS.size());
|
log.info("Registered {} event listeners.", LISTENERS.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user