implement logging feature base

This commit is contained in:
Lee
2024-07-02 18:21:24 +01:00
parent 0b8caf3e25
commit 8ce3a5d25c
17 changed files with 641 additions and 23 deletions

View File

@ -66,19 +66,28 @@ public class DiscordMessageService extends ListenerAdapter {
@Override
public void onMessageUpdate(@NotNull MessageUpdateEvent event) {
Optional<DiscordMessage> message = discordMessageRepository.findById(event.getMessageId());
if (message.isPresent()) {
DiscordMessage discordMessage = message.get();
if (discordMessage.getContent().equals(event.getMessage().getContentStripped())) {
DiscordMessage oldMessage = message.orElse(null);
if (oldMessage != null) {
if (oldMessage.getContent().equals(event.getMessage().getContentStripped())) {
return;
}
discordMessage.setContent(event.getMessage().getContentStripped());
discordMessageRepository.save(discordMessage);
discordMessageRepository.delete(oldMessage);
}
DiscordMessage newMessage = new DiscordMessage(
event.getMessageId(),
event.getMessage().getTimeCreated().toInstant().toEpochMilli(),
event.getChannel().getId(),
event.getGuild().getId(),
event.getAuthor().getId(),
event.getMessage().getContentStripped(),
false
);
discordMessageRepository.save(newMessage);
BatGuild guild = guildService.getGuild(event.getGuild().getId());
BatUser user = userService.getUser(event.getAuthor().getId());
for (EventListener listener : EventService.LISTENERS) {
listener.onGuildMessageEdit(guild, user, event);
listener.onGuildMessageEdit(guild, user, oldMessage, newMessage, event);
}
}

View File

@ -14,7 +14,6 @@ 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;
@ -101,19 +100,6 @@ 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());