From 59813fe37b79171ee09493c39342888cf841b71a Mon Sep 17 00:00:00 2001 From: Sebastien Date: Thu, 26 Apr 2018 17:32:38 +0200 Subject: [PATCH] Add multiserver to spam --- src/main/java/net/Broken/Commands/Spam.java | 30 ++++++------- .../java/net/Broken/Commands/SpamInfo.java | 35 ++++++++-------- src/main/java/net/Broken/Commands/Test.java | 2 +- src/main/java/net/Broken/MainBot.java | 7 ++-- .../RestApi/UserManagerAPIController.java | 1 - src/main/java/net/Broken/Tools/AntiSpam.java | 30 ++++++------- .../java/net/Broken/Tools/Moderateur.java | 26 ++++++------ .../java/net/Broken/audio/WebLoadUtils.java | 2 +- src/main/resources/static/error/404.html | 42 +++++++++++-------- src/main/resources/static/js/navabar.js | 6 ++- 10 files changed, 96 insertions(+), 85 deletions(-) diff --git a/src/main/java/net/Broken/Commands/Spam.java b/src/main/java/net/Broken/Commands/Spam.java index acd366a..fa6621d 100644 --- a/src/main/java/net/Broken/Commands/Spam.java +++ b/src/main/java/net/Broken/Commands/Spam.java @@ -25,7 +25,7 @@ import java.util.Objects; * Spam admin command */ public class Spam implements Commande { - Logger logger = LogManager.getLogger(); + private Logger logger = LogManager.getLogger(); @Override public void action(String[] args, MessageReceivedEvent event) @@ -97,7 +97,7 @@ public class Spam implements Commande { /**************************** * On recupere l'utilisateur et le role cible ****************************/ - List userL = event.getMessage().getMentionedUsers(); + List userL = event.getMessage().getMentionedMembers(); /**************************** @@ -114,14 +114,14 @@ public class Spam implements Commande { new MessageTimeOut(messages,MainBot.messageTimeOut).start(); } else { - Member user = serveur.getMember(userL.get(0)); + Member user = userL.get(0); logger.info("Tentative de pardon de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); /**************************** * virif si en spammer * ****************************/ - if (MainBot.spamUtils.containsKey(user.getUser())) { - if (MainBot.spamUtils.get(user.getUser()).isOnSpam()) { - MainBot.spamUtils.get(user.getUser()).setOnSpam(false); + if (MainBot.spamUtils.containsKey(user)) { + if (MainBot.spamUtils.get(user).isOnSpam()) { + MainBot.spamUtils.get(user).setOnSpam(false); } else { logger.warn("Utilisateur pas en spam."); Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete(); @@ -192,9 +192,9 @@ public class Spam implements Commande { /**************************** * virif pas deja en spammer * ****************************/ - if(MainBot.spamUtils.containsKey(user.getUser())) + if(MainBot.spamUtils.containsKey(user)) { - if(!MainBot.spamUtils.get(user.getUser()).isOnSpam()) + if(!MainBot.spamUtils.get(user).isOnSpam()) { this.goSpam(user,multiStr,serveur,event); } @@ -242,7 +242,7 @@ public class Spam implements Commande { /**************************** * On recupere l'utilisateur et le role cible ****************************/ - List userL = event.getMessage().getMentionedUsers(); + List userL = event.getMessage().getMentionedMembers(); /**************************** @@ -260,14 +260,14 @@ public class Spam implements Commande { } else { - Member user = serveur.getMember(userL.get(0)); + Member user = userL.get(0); logger.info("Tentative de reset de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); /**************************** * verif utilisteur trouver * ****************************/ - if (MainBot.spamUtils.containsKey(user.getUser())) { + if (MainBot.spamUtils.containsKey(user)) { logger.info("Reset du multiplicateur de " + user.getEffectiveName() + " réussi"); Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n *Le multiplcicateur de " + user.getEffectiveName() + " a été remit a zéro.*").complete(); List messages = new ArrayList(){{ @@ -275,7 +275,7 @@ public class Spam implements Commande { add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - MainBot.spamUtils.remove(user.getUser()); + MainBot.spamUtils.remove(user); } @@ -297,7 +297,7 @@ public class Spam implements Commande { if (args[0].equals("all")) { logger.info("Reset automatique des multiplicateur."); - for (User unUser: MainBot.spamUtils.keySet() ) //=for(int i=0; i())); - MainBot.spamUtils.get(user.getUser()).setMultip(multi); + MainBot.spamUtils.put(user,new UserSpamUtils(user,new ArrayList<>())); + MainBot.spamUtils.get(user).setMultip(multi); } new AntiSpam().extermine(user,serveur,serveur.getManager(),false,event); diff --git a/src/main/java/net/Broken/Commands/SpamInfo.java b/src/main/java/net/Broken/Commands/SpamInfo.java index 99b8134..48b067f 100644 --- a/src/main/java/net/Broken/Commands/SpamInfo.java +++ b/src/main/java/net/Broken/Commands/SpamInfo.java @@ -8,6 +8,7 @@ import net.Broken.Tools.PrivateMessage; import net.Broken.Tools.UserSpamUtils; import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.entities.ChannelType; +import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; @@ -24,41 +25,41 @@ import java.util.concurrent.TimeUnit; * Spam Info Command */ public class SpamInfo implements Commande{ - private HashMap threadHashMap = new HashMap<>(); + private HashMap threadHashMap = new HashMap<>(); Logger logger = LogManager.getLogger(); @Override public void action(String[] args, MessageReceivedEvent event) { - User user; + Member user; if(event.getMessage().getMentionedUsers().size() == 0){ - user = event.getAuthor(); + user = event.getMember(); } else { - user = event.getMessage().getMentionedUsers().get(0); + user = event.getMessage().getMentionedMembers().get(0); } Message message = null; if(!MainBot.spamUtils.containsKey(user)){ if(!event.isFromType(ChannelType.PRIVATE)) - message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).complete(); + message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).complete(); else - PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger); + PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger); } else{ UserSpamUtils util = MainBot.spamUtils.get(user); if(!util.isOnSpam()){ if(!event.isFromType(ChannelType.PRIVATE)) - message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); + message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); else - PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger); + PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger); } else{ if(!event.isFromType(ChannelType.PRIVATE)) - message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); + message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); else - message = PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`"),logger); + message = PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`"),logger); } } if(message != null){ @@ -139,9 +140,9 @@ public class SpamInfo implements Commande{ public UserSpamUtils util; public boolean stop; private int oldValue; - private User user; + private Member user; - public MessageUpdater(Message message,Message command, UserSpamUtils util,User user) { + public MessageUpdater(Message message,Message command, UserSpamUtils util, Member user) { this.message = message; this.util = util; this.user = user; @@ -151,14 +152,14 @@ public class SpamInfo implements Commande{ @Override public void run() { - logger.debug("Start "+user.getName()+" theard!"); + logger.debug("Start "+user.getEffectiveName()+" theard!"); if(util != null){ oldValue = util.getTimeLeft(); while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){ try { Thread.sleep(500); if(util.getTimeLeft()%5 == 0 && oldValue - util.getTimeLeft() >= 5){ - message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); + message.editMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); oldValue = util.getTimeLeft(); } @@ -166,14 +167,14 @@ public class SpamInfo implements Commande{ e.printStackTrace(); } } - logger.debug("Kill "+user.getName()+" theard!"); + logger.debug("Kill "+user.getEffectiveName()+" theard!"); if(stop) message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete(); else - message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); + message.editMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); } - logger.debug("Timer for message deletion of "+user.getName()+" stated..."); + logger.debug("Timer for message deletion of "+user.getEffectiveName()+" stated..."); threadHashMap.remove(user); List messages = new ArrayList<>(); messages.add(command); diff --git a/src/main/java/net/Broken/Commands/Test.java b/src/main/java/net/Broken/Commands/Test.java index 46a38a3..34aee15 100644 --- a/src/main/java/net/Broken/Commands/Test.java +++ b/src/main/java/net/Broken/Commands/Test.java @@ -10,7 +10,7 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import java.io.IOException; -public class ytTest implements Commande { +public class Test implements Commande { @Override public void action(String[] args, MessageReceivedEvent event) { event.getJDA().getPresence().setPresence(RichPresence.playing("test").asRichPresence(),false); diff --git a/src/main/java/net/Broken/MainBot.java b/src/main/java/net/Broken/MainBot.java index 181582e..4ab4a1a 100644 --- a/src/main/java/net/Broken/MainBot.java +++ b/src/main/java/net/Broken/MainBot.java @@ -10,6 +10,7 @@ import net.Broken.audio.Youtube.YoutubeTools; import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.ChannelType; +import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; @@ -33,10 +34,10 @@ import java.util.HashMap; public class MainBot { public static HashMap commandes = new HashMap<>(); - public static HashMap> historique =new HashMap<>(); - public static HashMap message_compteur =new HashMap<>(); + public static HashMap> historique =new HashMap<>(); + public static HashMap message_compteur =new HashMap<>(); public static boolean roleFlag = false; - public static HashMap spamUtils = new HashMap<>(); + public static HashMap spamUtils = new HashMap<>(); public static JDA jda; public static boolean ready = false; diff --git a/src/main/java/net/Broken/RestApi/UserManagerAPIController.java b/src/main/java/net/Broken/RestApi/UserManagerAPIController.java index 30cdd78..2d16375 100644 --- a/src/main/java/net/Broken/RestApi/UserManagerAPIController.java +++ b/src/main/java/net/Broken/RestApi/UserManagerAPIController.java @@ -64,7 +64,6 @@ public class UserManagerAPIController { @RequestMapping(value = "/confirmAccount", method = RequestMethod.POST) public ResponseEntity confirAccount(@RequestBody ConfirmData data){ - //TODO move pending user to accepted and return right things try { PendingUserEntity pUser = userUtils.confirmCheckToken(pendingUserRepository, Integer.parseInt(data.id), data.checkToken); UserEntity user = new UserEntity(pUser, userUtils.generateApiToken()); diff --git a/src/main/java/net/Broken/Tools/AntiSpam.java b/src/main/java/net/Broken/Tools/AntiSpam.java index 6d0dddb..bf4a44b 100644 --- a/src/main/java/net/Broken/Tools/AntiSpam.java +++ b/src/main/java/net/Broken/Tools/AntiSpam.java @@ -43,37 +43,37 @@ public class AntiSpam { } // On créer un nouvelle case dans le tableau des statuts si il n'y est pas - if(!MainBot.spamUtils.containsKey(user.getUser())) + if(!MainBot.spamUtils.containsKey(user)) { List messages = new ArrayList<>(); - messages.addAll(MainBot.historique.get(user.getUser())); - MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user,messages)); + messages.addAll(MainBot.historique.get(user)); + MainBot.spamUtils.put(user,new UserSpamUtils(user,messages)); } // On verrifie que l'uttilisateur n'est pas deja en spam - if(!MainBot.spamUtils.get(user.getUser()).isOnSpam()) + if(!MainBot.spamUtils.get(user).isOnSpam()) { //l'utilisateur n'est pas deja en spam - if(MainBot.spamUtils.get(user.getUser()).getMultip() != 0) + if(MainBot.spamUtils.get(user).getMultip() != 0) { - if(MainBot.spamUtils.get(user.getUser()).getMultip()<45 && incrMulti) + if(MainBot.spamUtils.get(user).getMultip()<45 && incrMulti) { - MainBot.spamUtils.get(user.getUser()).setMultip(MainBot.spamUtils.get(user.getUser()).getMultip()*2); + MainBot.spamUtils.get(user).setMultip(MainBot.spamUtils.get(user).getMultip()*2); } } else - MainBot.spamUtils.get(user.getUser()).setMultip(1); + MainBot.spamUtils.get(user).setMultip(1); - logger.info("Punition de "+user.getEffectiveName()+" avec un multiplicateur de "+MainBot.spamUtils.get(user.getUser())); + logger.info("Punition de "+user.getEffectiveName()+" avec un multiplicateur de "+MainBot.spamUtils.get(user)); - if(!MainBot.spamUtils.get(user.getUser()).isOnSpam()) + if(!MainBot.spamUtils.get(user).isOnSpam()) { - MainBot.spamUtils.get(user.getUser()).setOnSpam(true); + MainBot.spamUtils.get(user).setOnSpam(true); List spm = guild.getRolesByName("Spammer", false); try{ move.exc(user, spm, true, guild, guildManager); - MainBot.spamUtils.get(user.getUser()).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete()); - MainBot.spamUtils.get(user.getUser()).setMinuteur(new Minuteur(MainBot.spamUtils.get(user.getUser()).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event)); - MainBot.spamUtils.get(user.getUser()).launchMinuteur(); + 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(){{ @@ -81,7 +81,7 @@ public class AntiSpam { add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - MainBot.spamUtils.get(user.getUser()).setOnSpam(false); + MainBot.spamUtils.get(user).setOnSpam(false); } } diff --git a/src/main/java/net/Broken/Tools/Moderateur.java b/src/main/java/net/Broken/Tools/Moderateur.java index c38cc0f..7da5190 100644 --- a/src/main/java/net/Broken/Tools/Moderateur.java +++ b/src/main/java/net/Broken/Tools/Moderateur.java @@ -41,19 +41,19 @@ public class Moderateur { int nbMessage = 3; int spam = 0; - if(MainBot.spamUtils.containsKey(user.getUser()) && MainBot.spamUtils.get(user.getUser()).isOnSpam()){ - MainBot.spamUtils.get(user.getUser()).addMessage(event.getMessage()); + if(MainBot.spamUtils.containsKey(user) && MainBot.spamUtils.get(user).isOnSpam()){ + MainBot.spamUtils.get(user).addMessage(event.getMessage()); } /******************************************** * si l'USER a deja envoyé un message * ********************************************/ - if(MainBot.historique.containsKey(user.getUser()))// Si le user a deja posté un message + if(MainBot.historique.containsKey(user))// Si le user a deja posté un message { /******************************************** * COPIE des infos d"historique" vers TOI[] * ********************************************/ - thisUserHistory = (ArrayList) MainBot.historique.get(user.getUser()).clone(); + thisUserHistory = (ArrayList) MainBot.historique.get(user).clone(); /******************************************** * Ajout dernier message recu + dans histo' * @@ -61,7 +61,7 @@ public class Moderateur { thisUserHistory.add(0,event.getMessage()); if(thisUserHistory.size()>nbMessage+1) thisUserHistory.remove(4); - MainBot.historique.put(user.getUser(), thisUserHistory);// On ajoute dans l'historique TOI + MainBot.historique.put(user, thisUserHistory);// On ajoute dans l'historique TOI /***************************** * ANALYSE des messages * @@ -81,7 +81,7 @@ public class Moderateur { { logger.info("\t - "+aMessage.getContentRaw()); } - MainBot.historique.put(user.getUser(), new ArrayList()); + MainBot.historique.put(user, new ArrayList()); } } else { @@ -92,7 +92,7 @@ public class Moderateur { // on ajoute le dernier message dans "historique" thisUserHistory.add(0,event.getMessage()); - MainBot.historique.put(user.getUser(), thisUserHistory); + MainBot.historique.put(user, thisUserHistory); } /********************************** * AFFICHAGE DE HISTORIQUE * @@ -104,24 +104,24 @@ public class Moderateur { /******************************************** * Comptage du nombre de message * ********************************************/ - if(MainBot.message_compteur.containsKey(user.getUser()))// Si le user a deja posté un message + if(MainBot.message_compteur.containsKey(user))// Si le user a deja posté un message { - int cpt = MainBot.message_compteur.get(user.getUser()); + int cpt = MainBot.message_compteur.get(user); cpt++; //System.out.println("compteur : "+cpt); - MainBot.message_compteur.put(user.getUser(), cpt); + MainBot.message_compteur.put(user, cpt); if(cpt > 5){ - MainBot.message_compteur.put(user.getUser(),0); + MainBot.message_compteur.put(user,0); spam = 1; logger.info("Detection de spam pour "+user.getEffectiveName()+"avec 5 message en 5seg: "); - ArrayList histo = MainBot.historique.get(user.getUser()); + ArrayList histo = MainBot.historique.get(user); for (Message aMessage:histo ) { // logger.debug("\t*"+aMessage.getContent()); } } }else{ - MainBot.message_compteur.put(user.getUser(), 1); + MainBot.message_compteur.put(user, 1); } return spam; diff --git a/src/main/java/net/Broken/audio/WebLoadUtils.java b/src/main/java/net/Broken/audio/WebLoadUtils.java index e52c6d8..01c6f94 100644 --- a/src/main/java/net/Broken/audio/WebLoadUtils.java +++ b/src/main/java/net/Broken/audio/WebLoadUtils.java @@ -39,7 +39,7 @@ public class WebLoadUtils { public void trackLoaded(AudioTrack track) { logger.info("Single Track detected from web!"); - userAudioTrack = new UserAudioTrack(user, track); //TODO + userAudioTrack = new UserAudioTrack(user, track); if(submit) audioM.play(audioM.getGuild(), audioM.getPlayedChanel(), audioM.getGuildMusicManager(), userAudioTrack, data.onHead); response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK); diff --git a/src/main/resources/static/error/404.html b/src/main/resources/static/error/404.html index 125b939..c68705d 100644 --- a/src/main/resources/static/error/404.html +++ b/src/main/resources/static/error/404.html @@ -10,27 +10,22 @@ - - + + - - - - - -