From 608ae867e072b28a2acef1adff324a6542dd8aff Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sat, 28 Apr 2018 23:17:19 +0200 Subject: [PATCH] Test if spam role exist --- src/main/java/net/Broken/BotListener.java | 1 - src/main/java/net/Broken/Tools/AntiSpam.java | 44 ++++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/Broken/BotListener.java b/src/main/java/net/Broken/BotListener.java index c2fed17..1fd0029 100644 --- a/src/main/java/net/Broken/BotListener.java +++ b/src/main/java/net/Broken/BotListener.java @@ -118,7 +118,6 @@ public class BotListener extends ListenerAdapter { } - @Override public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) { super.onGuildVoiceLeave(event); diff --git a/src/main/java/net/Broken/Tools/AntiSpam.java b/src/main/java/net/Broken/Tools/AntiSpam.java index bf4a44b..1797cf2 100644 --- a/src/main/java/net/Broken/Tools/AntiSpam.java +++ b/src/main/java/net/Broken/Tools/AntiSpam.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -69,20 +70,27 @@ public class AntiSpam { { MainBot.spamUtils.get(user).setOnSpam(true); List spm = guild.getRolesByName("Spammer", false); - try{ - move.exc(user, spm, true, guild, guildManager); - MainBot.spamUtils.get(user).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete()); - MainBot.spamUtils.get(user).setMinuteur(new Minuteur(MainBot.spamUtils.get(user).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event)); - MainBot.spamUtils.get(user).launchMinuteur(); - }catch (HierarchyException e){ - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - MainBot.spamUtils.get(user).setOnSpam(false); + if(spm.size() != 0){ + try{ + move.exc(user, spm, true, guild, guildManager); + MainBot.spamUtils.get(user).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete()); + MainBot.spamUtils.get(user).setMinuteur(new Minuteur(MainBot.spamUtils.get(user).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event)); + MainBot.spamUtils.get(user).launchMinuteur(); + }catch (HierarchyException e){ + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete(); + List messages = new ArrayList(){{ + add(rest); + add(event.getMessage()); + }}; + new MessageTimeOut(messages,MainBot.messageTimeOut).start(); + MainBot.spamUtils.get(user).setOnSpam(false); + } } + else { + MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nSpam role not found, you need to create it!")); + event.getTextChannel().sendMessage(msg).complete(); + } + } } @@ -122,7 +130,7 @@ public class AntiSpam { @Override public void run() { logger.info("["+user.getEffectiveName()+"] Démarage pour "+multip+"min"); - while (MainBot.spamUtils.get(user.getUser()).isOnSpam()) + while (MainBot.spamUtils.get(user).isOnSpam()) { try { sleep(1000); @@ -148,9 +156,9 @@ public class AntiSpam { logger.error("Hierarchy error"); } logger.info("["+user.getEffectiveName()+"] Fin des "+multip+"min"); - new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user.getUser()).getMessages()),0).start(); - MainBot.spamUtils.get(user.getUser()).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete()); - new MessageTimeOut(MainBot.spamUtils.get(user.getUser()).getMessages(),60).start(); + new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user).getMessages()),0).start(); + MainBot.spamUtils.get(user).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete()); + new MessageTimeOut(MainBot.spamUtils.get(user).getMessages(),60).start(); // #-----------------------------------------------# @@ -160,4 +168,6 @@ public class AntiSpam { + + }