-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove event discord information if one output message gets deleted a…
…nd warn about this
- Loading branch information
1 parent
f25b141
commit 9abffef
Showing
6 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/java/de/webalf/slotbot/service/bot/listener/ChannelDeleteListener.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/main/java/de/webalf/slotbot/service/bot/listener/DeleteListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.webalf.slotbot.service.bot.listener; | ||
|
||
import de.webalf.slotbot.service.EventDiscordInformationService; | ||
import de.webalf.slotbot.service.bot.GuildBotService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; | ||
import net.dv8tion.jda.api.events.message.MessageDeleteEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.MessageSource; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* @author Alf | ||
* @since 03.04.2023 | ||
*/ | ||
@RequiredArgsConstructor(onConstructor_ = @Autowired) | ||
@Slf4j | ||
public class DeleteListener extends ListenerAdapter { | ||
private final EventDiscordInformationService eventDiscordInformationService; | ||
private final GuildBotService guildBotService; | ||
private final MessageSource messageSource; | ||
|
||
@Override | ||
public void onChannelDelete(@NotNull ChannelDeleteEvent event) { | ||
log.trace("Channel {} deleted in guild {}", event.getChannel().getId(), event.getGuild().getId()); | ||
eventDiscordInformationService.removeByChannel(event.getChannel().getIdLong()); | ||
} | ||
|
||
@Override | ||
public void onMessageDelete(@NotNull MessageDeleteEvent event) { | ||
if (!event.isFromGuild()) return; | ||
log.trace("Message {} deleted in channel {} in guild {}", event.getMessageId(), event.getChannel().getId(), event.getGuild().getId()); | ||
|
||
eventDiscordInformationService.removeByMessage(event.getChannel().getIdLong(), event.getMessageIdLong(), () -> { | ||
final Locale guildLocale = guildBotService.getGuildLocale(event.getGuild().getIdLong()); | ||
event.getChannel().sendMessage(messageSource.getMessage("event.discordInformation.broken", null, guildLocale)).queue(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters