forked from Fascinated/Bat
add message snipe feature
This commit is contained in:
@ -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()) {
|
||||
|
Reference in New Issue
Block a user