add message snipe feature

This commit is contained in:
Lee
2024-07-01 21:20:39 +01:00
parent 727a4c9a6f
commit 8b451c6ee5
16 changed files with 562 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.model.DiscordMessage;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
@ -11,7 +12,9 @@ import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameE
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
@ -36,11 +39,14 @@ public class EventService extends ListenerAdapter {
public static final Set<EventListener> LISTENERS = new HashSet<>();
private final GuildService guildService;
private final UserService userService;
private final DiscordMessageService discordMessageService;
@Autowired
public EventService(@NonNull GuildService guildService, @NonNull UserService userService, @NonNull ApplicationContext context) {
public EventService(@NonNull ApplicationContext context, @NonNull GuildService guildService, @NonNull UserService userService,
@NonNull DiscordMessageService discordMessageService) {
this.guildService = guildService;
this.userService = userService;
this.discordMessageService = discordMessageService;
DiscordService.JDA.addEventListener(this);
context.getBeansOfType(EventListener.class).values().forEach(this::registerListeners);
@ -95,6 +101,30 @@ public class EventService extends ListenerAdapter {
}
}
@Override
public void onMessageUpdate(@NotNull MessageUpdateEvent event) {
if (event.getAuthor().isBot()) {
return;
}
BatGuild guild = guildService.getGuild(event.getGuild().getId());
BatUser user = userService.getUser(event.getAuthor().getId());
for (EventListener listener : LISTENERS) {
listener.onGuildMessageEdit(guild, user, event);
}
}
@Override
public void onMessageDelete(@NotNull MessageDeleteEvent event) {
BatGuild guild = guildService.getGuild(event.getGuild().getId());
DiscordMessage message = discordMessageService.getMessage(event.getMessageId());
BatUser user = message == null ? null : userService.getUser(message.getAuthorId());
for (EventListener listener : LISTENERS) {
listener.onGuildMessageDelete(guild, user, message, event);
}
}
@Override
public void onStringSelectInteraction(StringSelectInteractionEvent event) {
if (event.getUser().isBot()) {