Correct some bug

This commit is contained in:
Unknown 2017-09-27 12:08:57 +02:00
parent 947fb39523
commit 9fd52e65ad
8 changed files with 107 additions and 57 deletions

View File

@ -1 +1 @@
worker: java -Dlog4j.configurationFile=log4j2.xml -jar Discord_Stroumpf_Beta.jar "MjQwODA2MDk1NzcyMTg4Njc0.CvIrrg.p3lOx7oXabPWcT1oZiPKcu0uSs4"
worker: java -Dlog4j.configurationFile=log4j2.xml -jar Discord_Stroumpf_Beta.jar -t MjQwODA2MDk1NzcyMTg4Njc0.CvIrrg.p3lOx7oXabPWcT1oZiPKcu0uSs4

View File

@ -1,19 +1,26 @@
package net.Broken;
import net.Broken.Commandes.Move;
import net.Broken.Commandes.Spam;
import net.Broken.Outils.AntiSpam;
import net.Broken.Outils.Moderateur;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.events.ExceptionEvent;
import net.dv8tion.jda.core.events.ReadyEvent;
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.core.events.guild.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.HierarchyException;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.managers.GuildManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import sun.security.tools.keytool.Main;
/**
@ -32,12 +39,36 @@ public class BotListener extends ListenerAdapter {
}
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
logger.info(event.getUser().getName()+ "join the guild, move it!");
new Move().exc(event.getMember(),event.getJDA().getRolesByName("Rat_d'égout",true).get(0),false,event.getJDA().getGuilds().get(0),event.getJDA().getGuilds().get(0).getManager());
MainBot.roleFlag = false;
}
@Override
public void onGuildMemberRoleRemove(GuildMemberRoleRemoveEvent event) {
logger.debug(event.getUser().getName()+" leave a role");
if(!MainBot.roleFlag){
if(event.getMember().getRoles().size() == 0){
logger.info(event.getUser().getName()+ "have no roles, move it!");
new Move().exc(event.getMember(),event.getJDA().getRolesByName("Rat_d'égout",true).get(0),false,event.getJDA().getGuilds().get(0),event.getJDA().getGuilds().get(0).getManager());
MainBot.roleFlag = false;
}
}
else
{
logger.debug("ignore it");
MainBot.roleFlag = false;
}
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
// ----------------------Test pour eviter eco de commande-------------------------
// try
// {
if (event.getMessage().getContent().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
//On a detecter que c'etait une commande
@ -47,23 +78,21 @@ public class BotListener extends ListenerAdapter {
else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
{
if(!event.getTextChannel().getName().equals("le_dongeon"))
{
Guild serveur=event.getGuild();
if(!event.isFromType(ChannelType.PRIVATE)) {
if (!event.getTextChannel().getName().equals("le_dongeon")) {
Guild serveur = event.getGuild();
GuildManager guildManager = serveur.getManager();
Member user = event.getMember();
if(!event.isFromType(ChannelType.PRIVATE))
{
// appel de la methode d'analyse de message de "Moderateur"
if(!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContent().length()>0) {
if (!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContent().length() > 0) {
if (modo.analyse(user, serveur, guildManager, event) == 1) {
antispam.extermine(user, serveur, guildManager,true, event);
antispam.extermine(user, serveur, guildManager, true, event);
}
}
else if(event.getMessage().getContent().length() == 0)
} else if (event.getMessage().getContent().length() == 0)
logger.error("Image detected, ignoring it.");
}
}
@ -72,14 +101,6 @@ public class BotListener extends ListenerAdapter {
}
// }catch (Exception e)
// {
// if (e.getMessage()==null) {
// logger.error("NullPointerException");
// } else {
// logger.error(e.getMessage());
// }
// }
}
}

View File

@ -1,9 +1,11 @@
package net.Broken.Commandes;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Outils.EmbedMessageUtils;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.HierarchyException;
import net.dv8tion.jda.core.managers.GuildController;
import net.dv8tion.jda.core.managers.GuildManager;
import org.apache.logging.log4j.LogManager;
@ -40,8 +42,9 @@ public class Move implements Commande {
* @param serveurManager
* @return
*/
public boolean exc(Member user, Role cible , boolean reset, Guild serveur, GuildManager serveurManager)
public boolean exc(Member user, Role cible , boolean reset, Guild serveur, GuildManager serveurManager) throws HierarchyException
{
MainBot.roleFlag = true;
guildController = new GuildController(serveur);
boolean erreur = false;
List<Role> allRoll = serveur.getRoles();
@ -98,7 +101,7 @@ public class Move implements Commande {
if(userL.size()<1 ||roleL.size()<1)
{
logger.info("Mentionnement Incorect.");
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError(":arrow_right: Utilisateur ou Role mal mentioner.")).queue();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Utilisateur ou Role mal mentioner.")).queue();
}
else
{
@ -111,15 +114,22 @@ public class Move implements Commande {
logger.info("Autorisation suffisante, deplacement autorisé");
logger.info("Utilisateur trouvée");
try {
boolean erreur=this.exc(user,roleCible,true,serveur,serveur.getManager());
if(erreur)
{
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError(":arrow_right: Verifier le rôle cible. ")).queue();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Verifier le rôle cible. ")).queue();
}
else
{
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveOk("Déplacement de "+user.getEffectiveName()+" vers "+roleCible.getName()+" reussi.")).queue();
}
}catch (HierarchyException e){
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).queue();
logger.error("Hierarchy error");
}
}
else
{
@ -133,12 +143,12 @@ public class Move implements Commande {
else
{
logger.warn("Arguments maquant.");
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError(":arrow_right: Arguments manquant.")).queue();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Arguments manquant.")).queue();
}
}
else
event.getPrivateChannel().sendMessage("\n:warning: **__Commande non disponible en priver!__** :warning:");
event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate());

View File

@ -153,7 +153,7 @@ public class SpamInfo implements Commande{
public void run() {
logger.debug("Start "+user.getName()+" theard!");
oldValue = util.getTimeLeft();
while (util.getTimeLeft()!=0 && !stop){
while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){
try {
Thread.sleep(500);
if(util.getTimeLeft()%5 == 0 && oldValue - util.getTimeLeft() >= 5){

View File

@ -33,6 +33,7 @@ public class MainBot {
public static boolean okInit=false;
public static HashMap<User, ArrayList<Message>> historique =new HashMap<>();
public static HashMap<User, Integer> message_compteur =new HashMap<>();
public static boolean roleFlag = false;
public static HashMap<User, UserSpamUtils> spamUtils = new HashMap<>();
@ -180,7 +181,7 @@ public class MainBot {
commandes.get(cmd.commande).executed(true, cmd.event);
}
else
cmd.event.getPrivateChannel().sendMessage("\n:warning: **__Commande non disponible en privé!__** :warning:").queue();
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
}

View File

@ -7,6 +7,7 @@ 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.exceptions.HierarchyException;
import net.dv8tion.jda.core.managers.GuildManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -61,14 +62,20 @@ public class AntiSpam {
logger.info("Punition de "+user.getEffectiveName()+" avec un multiplicateur de "+MainBot.spamUtils.get(user.getUser()));
event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).queue();
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
{
MainBot.spamUtils.get(user.getUser()).setOnSpam(true);
List<Role> spm = serveur.getRolesByName("Spammer", false);
try{
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()).setMinuteur(new Minuteur(MainBot.spamUtils.get(user.getUser()).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event));
MainBot.spamUtils.get(user.getUser()).launchMinuteur();
}catch (HierarchyException e){
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).queue();
MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
}
}
}
@ -118,7 +125,12 @@ public class AntiSpam {
timeLeft--;
}
logger.info("["+user.getEffectiveName()+"] Fin de spam pour "+user.getEffectiveName()+" apres "+multip+"min.");
try {
move.exc(user, saveRoleUser.get(0), true, serveur, serveurManager); //aSaveroleUser=saveRoleUser.get(i)
}catch (HierarchyException e){
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).queue();
logger.error("Hierarchy error");
}
logger.info("["+user.getEffectiveName()+"] Fin des "+multip+"min");
chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).queue();

View File

@ -2,6 +2,7 @@ package net.Broken.Outils;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
@ -13,6 +14,11 @@ public class EmbedMessageUtils {
}
public static MessageEmbed getNoPrivate(){
return new EmbedBuilder().setTitle(":warning: Commande non disponible en privé! :warning:").setDescription(":arrow_right: Utilisez `//help` pour voirs les commandes disponible.").setColor(Color.red).build();
}
public static MessageEmbed getSpamExtermine(Member autor, int multi) {
return new EmbedBuilder().setTitle(":mute: Spam Hunter :mute:").setDescription(autor.getAsMention() + " détecté comme spammer !\n\nOn te revoit dans __**" + multi + "**__ min!").setImage("https://media.giphy.com/media/WVudyGEaizNeg/giphy.gif").setFooter("Spam info disponible via '//spaminfo' en privé", null).setColor(Color.orange).build();
}
@ -30,7 +36,7 @@ public class EmbedMessageUtils {
}
public static MessageEmbed getMoveOk(String message) {
return new EmbedBuilder().setTitle(":ok: Move :ok: ").setDescription(message).setColor(Color.green).setFooter("'//help move' pour plus d'info ", null).build();
return new EmbedBuilder().setTitle(":arrow_left: Move :arrow_right: ").setDescription(message).setColor(Color.green).setFooter("'//help move' pour plus d'info ", null).build();
}
public static MessageEmbed getSpamError(String message) {

View File

@ -105,7 +105,7 @@ public class Moderateur {
spam = 1;
logger.info("Detection de spam pour "+user.getEffectiveName()+"avec 5 message en 5seg: ");
ArrayList<Message> histo = MainBot.historique.get(user.getUser());
for (Message aMessage:histo ) //=for(int i=0; i<saveRoleUser.size(); i++)
for (Message aMessage:histo )
{
logger.debug("\t*"+aMessage.getContent());
}