From 5f393b8283acde44642b02cb4daac92453ec99e6 Mon Sep 17 00:00:00 2001 From: danthe1st Date: Sun, 9 Jul 2023 12:44:04 +0200 Subject: [PATCH] timeout users on automod --- .../javabot/systems/moderation/AutoMod.java | 58 ++++++------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/javadiscord/javabot/systems/moderation/AutoMod.java b/src/main/java/net/javadiscord/javabot/systems/moderation/AutoMod.java index a93691e03..bd3217cba 100644 --- a/src/main/java/net/javadiscord/javabot/systems/moderation/AutoMod.java +++ b/src/main/java/net/javadiscord/javabot/systems/moderation/AutoMod.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Scanner; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -103,19 +104,6 @@ private boolean canBypassAutomod(Member member) { * @param message the {@link Message} that should be checked */ private void checkNewMessageAutomod(@Nonnull Message message) { - // mention spam - if (message.getMentions().getUsers().size() >= 5) { - new ModerationService(notificationService, botConfig.get(message.getGuild()), warnRepository, asyncPool) - .warn( - message.getAuthor(), - WarnSeverity.MEDIUM, - "Automod: Mention Spam", - message.getGuild().getMember(message.getJDA().getSelfUser()), - message.getChannel(), - false - ); - } - // spam message.getChannel().getHistory().retrievePast(10).queue(messages -> { int spamCount = (int) messages.stream().filter(msg -> !msg.equals(message)) @@ -138,39 +126,31 @@ private void checkNewMessageAutomod(@Nonnull Message message) { private void checkContentAutomod(@Nonnull Message message) { //Check for Advertising Links if (hasAdvertisingLink(message)) { - notificationService.withGuild(message.getGuild()).sendToModerationLog(c -> c.sendMessageFormat("Message: `%s`", message.getContentRaw())); - new ModerationService(notificationService, botConfig.get(message.getGuild()), warnRepository, asyncPool) - .warn( - message.getAuthor(), - WarnSeverity.MEDIUM, - "Automod: Advertising", - message.getGuild().getMember(message.getJDA().getSelfUser()), - message.getChannel(), - isSuggestionsChannel(message.getChannel()) - ); - message.delete().queue(success -> { - }, error -> log.info("Message was deleted before Automod was able to handle it.")); - - + doAutomodActions(message,"Advertising"); } //Check for suspicious Links if (hasSuspiciousLink(message)) { - notificationService.withGuild(message.getGuild()).sendToModerationLog(c -> c.sendMessageFormat("Suspicious Link sent by: %s (`%s`)", message.getAuthor().getAsMention(), message.getContentRaw())); - new ModerationService(notificationService, botConfig.get(message.getGuild()), warnRepository, asyncPool) - .warn( - message.getAuthor(), - WarnSeverity.MEDIUM, - "Automod: Suspicious Link", - message.getGuild().getMember(message.getJDA().getSelfUser()), - message.getChannel(), - isSuggestionsChannel(message.getChannel()) - ); - message.delete().queue(success -> { - }, error -> log.info("Message was deleted before Automod was able to handle it.")); + doAutomodActions(message, "Suspicious Link"); } } + private void doAutomodActions(Message message, String reason) { + notificationService.withGuild(message.getGuild()).sendToModerationLog(c -> c.sendMessageFormat("Message by %s: `%s`", message.getAuthor().getAsMention(), message.getContentRaw())); + new ModerationService(notificationService, botConfig.get(message.getGuild()), warnRepository, asyncPool) + .warn( + message.getAuthor(), + WarnSeverity.MEDIUM, + "Automod: " + reason, + message.getGuild().getMember(message.getJDA().getSelfUser()), + message.getChannel(), + isSuggestionsChannel(message.getChannel()) + ); + message.delete().queue(success -> { + }, error -> log.info("Message was deleted before Automod was able to handle it.")); + message.getMember().timeoutFor(30, TimeUnit.SECONDS).queue(); + } + /** * Handles potential spam messages. *