AntiSpam now delete spam message!
This commit is contained in:
parent
00f0c04f37
commit
b1f33149b9
@ -3,6 +3,7 @@ package net.Broken;
|
|||||||
import net.Broken.Commandes.Move;
|
import net.Broken.Commandes.Move;
|
||||||
import net.Broken.Commandes.Spam;
|
import net.Broken.Commandes.Spam;
|
||||||
import net.Broken.Outils.AntiSpam;
|
import net.Broken.Outils.AntiSpam;
|
||||||
|
import net.Broken.Outils.MessageTimeOut;
|
||||||
import net.Broken.Outils.Moderateur;
|
import net.Broken.Outils.Moderateur;
|
||||||
import net.dv8tion.jda.core.JDA;
|
import net.dv8tion.jda.core.JDA;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
|
@ -15,6 +15,7 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -320,7 +321,7 @@ public class Spam implements Commande {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user));
|
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user,new ArrayList<>()));
|
||||||
MainBot.spamUtils.get(user.getUser()).setMultip(multi);
|
MainBot.spamUtils.get(user.getUser()).setMultip(multi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.Broken.Commandes;
|
|||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.Outils.EmbedMessageUtils;
|
import net.Broken.Outils.EmbedMessageUtils;
|
||||||
|
import net.Broken.Outils.MessageTimeOut;
|
||||||
import net.Broken.Outils.PrivateMessage;
|
import net.Broken.Outils.PrivateMessage;
|
||||||
import net.Broken.Outils.UserSpamUtils;
|
import net.Broken.Outils.UserSpamUtils;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
@ -15,7 +16,9 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,14 +181,11 @@ public class SpamInfo implements Commande{
|
|||||||
}
|
}
|
||||||
logger.debug("Timer for message deletion of "+user.getName()+" stated...");
|
logger.debug("Timer for message deletion of "+user.getName()+" stated...");
|
||||||
threadHashMap.remove(user);
|
threadHashMap.remove(user);
|
||||||
try {
|
List<Message> messages = new ArrayList<>();
|
||||||
Thread.sleep(15000);
|
messages.add(command);
|
||||||
logger.debug("Delete "+user.getName()+" messages");
|
messages.add(message);
|
||||||
message.delete().queue();
|
new MessageTimeOut(messages,15).start();
|
||||||
command.delete().queue();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@ package net.Broken.Outils;
|
|||||||
|
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.Commandes.Move;
|
import net.Broken.Commandes.Move;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.*;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
|
||||||
import net.dv8tion.jda.core.entities.Role;
|
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.core.exceptions.HierarchyException;
|
import net.dv8tion.jda.core.exceptions.HierarchyException;
|
||||||
import net.dv8tion.jda.core.managers.GuildManager;
|
import net.dv8tion.jda.core.managers.GuildManager;
|
||||||
@ -13,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static java.lang.Thread.sleep;
|
import static java.lang.Thread.sleep;
|
||||||
@ -44,7 +42,9 @@ public class AntiSpam {
|
|||||||
// On créer un nouvelle case dans le tableau des statuts si il n'y est pas
|
// 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.getUser()))
|
||||||
{
|
{
|
||||||
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user));
|
List<Message> messages = new ArrayList<>();
|
||||||
|
messages.addAll(MainBot.historique.get(user.getUser()));
|
||||||
|
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user,messages));
|
||||||
}
|
}
|
||||||
// On verrifie que l'uttilisateur n'est pas deja en spam
|
// On verrifie que l'uttilisateur n'est pas deja en spam
|
||||||
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
||||||
@ -68,7 +68,7 @@ public class AntiSpam {
|
|||||||
List<Role> spm = serveur.getRolesByName("Spammer", false);
|
List<Role> spm = serveur.getRolesByName("Spammer", false);
|
||||||
try{
|
try{
|
||||||
move.exc(user, spm.get(0), true, serveur, serveurManger);
|
move.exc(user, spm.get(0), true, serveur, serveurManger);
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).queue();
|
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()).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.getUser()).launchMinuteur();
|
||||||
}catch (HierarchyException e){
|
}catch (HierarchyException e){
|
||||||
@ -132,7 +132,9 @@ public class AntiSpam {
|
|||||||
logger.error("Hierarchy error");
|
logger.error("Hierarchy error");
|
||||||
}
|
}
|
||||||
logger.info("["+user.getEffectiveName()+"] Fin des "+multip+"min");
|
logger.info("["+user.getEffectiveName()+"] Fin des "+multip+"min");
|
||||||
chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).queue();
|
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();
|
||||||
|
|
||||||
// #-----------------------------------------------#
|
// #-----------------------------------------------#
|
||||||
|
|
||||||
|
41
src/net/Broken/Outils/MessageTimeOut.java
Normal file
41
src/net/Broken/Outils/MessageTimeOut.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package net.Broken.Outils;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
|
import net.dv8tion.jda.core.exceptions.ErrorResponseException;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MessageTimeOut extends Thread{
|
||||||
|
List<Message> messages;
|
||||||
|
int second;
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
|
public MessageTimeOut(List<Message> messages, int second) {
|
||||||
|
this.messages = messages;
|
||||||
|
this.second = second;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
logger.debug("Timer for message deletion stated...");
|
||||||
|
for(int i=0; i<second; i++){
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Message aMessage: messages)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
logger.debug(aMessage.getContent());
|
||||||
|
aMessage.delete().complete();
|
||||||
|
}catch (ErrorResponseException e){
|
||||||
|
logger.warn("Unknown Message");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -32,12 +32,15 @@ public class Moderateur {
|
|||||||
int nbMessage = 3;
|
int nbMessage = 3;
|
||||||
int spam = 0;
|
int spam = 0;
|
||||||
|
|
||||||
|
if(MainBot.spamUtils.containsKey(user.getUser()) && MainBot.spamUtils.get(user.getUser()).isOnSpam()){
|
||||||
|
MainBot.spamUtils.get(user.getUser()).addMessage(event.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************
|
/********************************************
|
||||||
* si l'USER a deja envoyé un message *
|
* 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.getUser()))// Si le user a deja posté un message
|
||||||
{
|
{
|
||||||
logger.debug("ok");
|
|
||||||
/********************************************
|
/********************************************
|
||||||
* COPIE des infos d"historique" vers TOI[] *
|
* COPIE des infos d"historique" vers TOI[] *
|
||||||
********************************************/
|
********************************************/
|
||||||
@ -60,7 +63,6 @@ public class Moderateur {
|
|||||||
if(aMessage.getContent().equals(oldMessage))
|
if(aMessage.getContent().equals(oldMessage))
|
||||||
equalCont++;
|
equalCont++;
|
||||||
oldMessage = aMessage.getContent();
|
oldMessage = aMessage.getContent();
|
||||||
logger.debug( "\t- "+aMessage.getContent());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(equalCont >= nbMessage){
|
if(equalCont >= nbMessage){
|
||||||
@ -74,7 +76,6 @@ public class Moderateur {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug("ok else ");
|
|
||||||
/********************************************
|
/********************************************
|
||||||
* SI c'est le 1er message de l'USER *
|
* SI c'est le 1er message de l'USER *
|
||||||
********************************************/
|
********************************************/
|
||||||
@ -107,7 +108,7 @@ public class Moderateur {
|
|||||||
ArrayList<Message> histo = MainBot.historique.get(user.getUser());
|
ArrayList<Message> histo = MainBot.historique.get(user.getUser());
|
||||||
for (Message aMessage:histo )
|
for (Message aMessage:histo )
|
||||||
{
|
{
|
||||||
logger.debug("\t*"+aMessage.getContent());
|
// logger.debug("\t*"+aMessage.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package net.Broken.Outils;
|
package net.Broken.Outils;
|
||||||
|
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UserSpamUtils {
|
public class UserSpamUtils {
|
||||||
private AntiSpam.Minuteur minuteur;
|
private AntiSpam.Minuteur minuteur;
|
||||||
private Member user;
|
private Member user;
|
||||||
private int multip = 0;
|
private int multip = 0;
|
||||||
private boolean onSpam = false;
|
private boolean onSpam = false;
|
||||||
|
private List<Message> messages;
|
||||||
|
|
||||||
public int getTimeLeft(){
|
public int getTimeLeft(){
|
||||||
return minuteur.timeLeft;
|
return minuteur.timeLeft;
|
||||||
@ -17,8 +21,9 @@ public class UserSpamUtils {
|
|||||||
return multip;
|
return multip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSpamUtils(Member user) {
|
public UserSpamUtils(Member user, List<Message> messages) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.messages = messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -45,4 +50,17 @@ public class UserSpamUtils {
|
|||||||
public Member getUser() {
|
public Member getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMessage(Message message){
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Message> getMessages() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAndAdd(Message message){
|
||||||
|
messages.clear();
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user