Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public ErrorAnalyzer() {
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getAuthor().isBot()) return;
if (HoneyPotHandler.isHoneyPot(event.getGuild(), event.getChannel())) return;

// exclude certain channels.
if (ServerSettings.shouldNotCheckError(event.getChannel())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.geysermc.discordbot.listeners;

import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
Expand All @@ -35,8 +35,6 @@
import org.geysermc.discordbot.util.ModerationHelper;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class HoneyPotHandler extends ListenerAdapter {
@Override
public void onReady(@NotNull ReadyEvent event) {
Expand Down Expand Up @@ -69,11 +67,16 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if (event.getAuthor().isBot()) return;
if (!event.isFromGuild()) return;

String honeyPotChannelId = GeyserBot.storageManager.getServerPreference(event.getGuild().getIdLong(), "honey-pot-channel");
if (honeyPotChannelId == null) return;

if (event.getChannel().getId().equals(honeyPotChannelId)) {
if (isHoneyPot(event.getGuild(), event.getChannel())) {
ModerationHelper.quarantineMember(event.getMember(), event.getGuild(), "Messaged in the honey pot channel.", false, null, event.getMessage(), true);
}
}

public static boolean isHoneyPot(Guild guild, Channel channel) {
String honeyPotChannelId = GeyserBot.storageManager.getServerPreference(guild.getIdLong(), "honey-pot-channel");
if (honeyPotChannelId == null) {
return false;
}
return channel.getId().equals(honeyPotChannelId);
}
}
14 changes: 3 additions & 11 deletions src/main/java/org/geysermc/discordbot/storage/ServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import org.apache.commons.lang3.StringUtils;
import org.geysermc.discordbot.GeyserBot;
Expand Down Expand Up @@ -194,19 +193,12 @@ public static boolean shouldNotLogChannel(MessageChannel channel) {
* @return If we should exclude the channel
*/
public static boolean shouldNotCheckError(MessageChannel channel) {
Guild server = getGuild(channel);

if (server == null) {
return true;
}

// Ignore file handling in Honeypot channels
String honeyPotChannelId = GeyserBot.storageManager.getServerPreference(server.getIdLong(), "honey-pot-channel");
if (honeyPotChannelId != null && honeyPotChannelId.equals(channel.getId())) {
Guild guild = getGuild(channel);
if (guild == null) {
return true;
}

return getList(channel.getIdLong(), "dont-check-error").contains(channel.getId());
return getList(guild.getIdLong(), "dont-check-error").contains(channel.getId());
}

/**
Expand Down
Loading