Test if spam role exist

This commit is contained in:
Sebastien 2018-04-28 23:17:19 +02:00
parent ad31172485
commit 608ae867e0
2 changed files with 27 additions and 18 deletions

View File

@ -118,7 +118,6 @@ public class BotListener extends ListenerAdapter {
} }
@Override @Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) { public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
super.onGuildVoiceLeave(event); super.onGuildVoiceLeave(event);

View File

@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -69,20 +70,27 @@ public class AntiSpam {
{ {
MainBot.spamUtils.get(user).setOnSpam(true); MainBot.spamUtils.get(user).setOnSpam(true);
List<Role> spm = guild.getRolesByName("Spammer", false); List<Role> spm = guild.getRolesByName("Spammer", false);
try{ if(spm.size() != 0){
move.exc(user, spm, true, guild, guildManager); try{
MainBot.spamUtils.get(user).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete()); move.exc(user, spm, true, guild, guildManager);
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).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete());
MainBot.spamUtils.get(user).launchMinuteur(); MainBot.spamUtils.get(user).setMinuteur(new Minuteur(MainBot.spamUtils.get(user).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event));
}catch (HierarchyException e){ MainBot.spamUtils.get(user).launchMinuteur();
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete(); }catch (HierarchyException e){
List<Message> messages = new ArrayList<Message>(){{ Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete();
add(rest); List<Message> messages = new ArrayList<Message>(){{
add(event.getMessage()); add(rest);
}}; add(event.getMessage());
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); }};
MainBot.spamUtils.get(user).setOnSpam(false); 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 @Override
public void run() { public void run() {
logger.info("["+user.getEffectiveName()+"] Démarage pour "+multip+"min"); logger.info("["+user.getEffectiveName()+"] Démarage pour "+multip+"min");
while (MainBot.spamUtils.get(user.getUser()).isOnSpam()) while (MainBot.spamUtils.get(user).isOnSpam())
{ {
try { try {
sleep(1000); sleep(1000);
@ -148,9 +156,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");
new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user.getUser()).getMessages()),0).start(); new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user).getMessages()),0).start();
MainBot.spamUtils.get(user.getUser()).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete()); MainBot.spamUtils.get(user).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete());
new MessageTimeOut(MainBot.spamUtils.get(user.getUser()).getMessages(),60).start(); new MessageTimeOut(MainBot.spamUtils.get(user).getMessages(),60).start();
// #-----------------------------------------------# // #-----------------------------------------------#
@ -160,4 +168,6 @@ public class AntiSpam {
} }