only allow sniped messages to be sniped for 1 hour after deletion
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m22s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m22s
This commit is contained in:
parent
d9dd175174
commit
b5ac5d6a9b
@ -1,7 +1,6 @@
|
||||
package cc.fascinated.bat.common;
|
||||
|
||||
import cc.fascinated.bat.config.Config;
|
||||
import io.sentry.Sentry;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
@ -7,8 +7,6 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
|
@ -16,7 +16,10 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
|
@ -7,7 +7,6 @@ import cc.fascinated.bat.features.leveling.LevelingProfile;
|
||||
import cc.fascinated.bat.features.leveling.UserLevel;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.UserService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
@ -17,7 +16,6 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
@ -27,6 +28,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
|
||||
* The sniped messages for each guild
|
||||
*/
|
||||
private static final Map<BatGuild, List<SnipedMessage>> snipedMessages = new HashMap<>();
|
||||
private static final long SNIPED_MESSAGE_EXPIRATION = TimeUnit.HOURS.toMillis(1);
|
||||
|
||||
@Autowired
|
||||
public MessageSnipeFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
@ -56,7 +58,9 @@ public class MessageSnipeFeature extends Feature implements EventListener {
|
||||
* @return the sniped messages for the given guild
|
||||
*/
|
||||
public static SnipedMessage getDeletedMessage(BatGuild guild, String channelId) {
|
||||
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>()).stream().filter(message -> message.getDeletedDate() != null)
|
||||
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>()).stream()
|
||||
.filter(message -> message.getDeletedDate() != null
|
||||
&& message.getDeletedDate().getTime() + SNIPED_MESSAGE_EXPIRATION > System.currentTimeMillis())
|
||||
.sorted(Comparator.comparing(SnipedMessage::getDeletedDate).reversed()).toList();
|
||||
for (SnipedMessage message : messages) {
|
||||
if (message.getDeletedDate() != null // Check if the message was deleted
|
||||
@ -86,13 +90,12 @@ public class MessageSnipeFeature extends Feature implements EventListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceive(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull MessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return;
|
||||
if (guild.getFeatureProfile().isFeatureDisabled(this)) {
|
||||
if (event.getAuthor().isBot() || guild.getFeatureProfile().isFeatureDisabled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
|
||||
if (messages.size() >= 10) {
|
||||
if (messages.size() >= 10) { // Only store the last 10 messages
|
||||
messages.remove(0);
|
||||
}
|
||||
messages.add(new SnipedMessage(event.getMessage(), null));
|
||||
|
@ -13,7 +13,6 @@ import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import org.apache.catalina.Server;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.mcutils.models.server.ServerPlatform;
|
||||
|
||||
|
@ -7,7 +7,6 @@ import cc.fascinated.bat.features.scoresaber.profile.guild.UserScoreFeedProfile;
|
||||
import cc.fascinated.bat.features.scoresaber.profile.user.ScoreSaberProfile;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
import cc.fascinated.bat.service.GuildService;
|
||||
import cc.fascinated.bat.service.UserService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.fascinated.bat.features.spotify.command;
|
||||
|
||||
import cc.fascinated.bat.Consts;
|
||||
import cc.fascinated.bat.Emojis;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
|
@ -6,7 +6,6 @@ import cc.fascinated.bat.common.Serializable;
|
||||
import cc.fascinated.bat.features.FeatureProfile;
|
||||
import cc.fascinated.bat.features.birthday.profile.BirthdayProfile;
|
||||
import cc.fascinated.bat.features.counter.CounterProfile;
|
||||
import cc.fascinated.bat.features.leveling.LevelingFeature;
|
||||
import cc.fascinated.bat.features.leveling.LevelingProfile;
|
||||
import cc.fascinated.bat.features.logging.LogProfile;
|
||||
import cc.fascinated.bat.features.minecraft.MinecraftProfile;
|
||||
|
@ -18,7 +18,6 @@ import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent;
|
||||
import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent;
|
||||
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
|
||||
import net.dv8tion.jda.api.events.guild.GuildUnbanEvent;
|
||||
import net.dv8tion.jda.api.events.guild.invite.GenericGuildInviteEvent;
|
||||
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
|
||||
|
@ -18,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user