forked from Fascinated/Bat
implement logging feature base
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
Reference in New Issue
Block a user