Multi guild for daily madame

This commit is contained in:
Sebastien 2018-04-29 16:14:29 +02:00
parent c06bdcd21a
commit 38eb8c39f7

View File

@ -4,11 +4,13 @@ import net.Broken.Commands.Over18.Madame;
import net.Broken.MainBot;
import net.Broken.Tools.DayListener.NewDayListener;
import net.Broken.Tools.Redirection;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.TextChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.List;
/**
* Daily Listener for DailyMadame
@ -21,31 +23,50 @@ public class DailyMadame implements NewDayListener{
boolean success=false;
boolean error=false;
int errorCp=0;
TextChannel chanel = MainBot.jda.getTextChannelsByName("nsfw-over18", true).get(0);
while(!success && !error)
{
try {
List<Guild> guilds = MainBot.jda.getGuilds();
String url = redirect.get("http://dites.bonjourmadame.fr/random");
logger.debug("URL: "+url);
if(Madame.scanPageForTipeee(url, logger)){
logger.debug("Advertisement detected! Retry! ("+url+")");
for(Guild guild : guilds){
TextChannel chanel = null;
for(TextChannel iterator : guild.getTextChannels())
{
if(iterator.isNSFW()){
chanel = iterator;
break;
}
else{
chanel.sendMessage("Le Daily Madame mes petits cochons :kissing_heart:\n" + url).queue();
success=true;
}
} catch (IOException e) {
errorCp++;
logger.warn("Erreur de redirection. (Essais n°"+errorCp+")");
if(errorCp>5)
{
logger.error("5 Erreur de redirection.");
error=true;
}
}
if(chanel != null){
while(!success && !error)
{
try {
String url = redirect.get("http://dites.bonjourmadame.fr/random");
logger.debug("URL: "+url);
if(Madame.scanPageForTipeee(url, logger)){
logger.debug("Advertisement detected! Retry! ("+url+")");
}
else{
chanel.sendMessage("Le Daily Madame mes petits cochons :kissing_heart:\n" + url).queue();
success=true;
}
} catch (IOException e) {
errorCp++;
logger.warn("Erreur de redirection. (Essais n°"+errorCp+")");
if(errorCp>5)
{
logger.error("5 Erreur de redirection.");
error=true;
}
}
}
}
else {
logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!");
}
}
}
}