From 70bc064cf788c3fd41f0f95b2c055b31b74133cd Mon Sep 17 00:00:00 2001 From: BrokenFire Date: Fri, 16 Feb 2018 15:37:10 +0100 Subject: [PATCH] Adding Daily Madame #5 --- .../net/Broken/Commands/Over18/Madame.java | 5 ++- src/main/java/net/Broken/Init.java | 2 + .../DayListener/Listeners/DailyMadame.java | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/Broken/Tools/DayListener/Listeners/DailyMadame.java diff --git a/src/main/java/net/Broken/Commands/Over18/Madame.java b/src/main/java/net/Broken/Commands/Over18/Madame.java index 90cd87c..4fd08a2 100644 --- a/src/main/java/net/Broken/Commands/Over18/Madame.java +++ b/src/main/java/net/Broken/Commands/Over18/Madame.java @@ -22,12 +22,13 @@ public class Madame implements Commande{ @Override public void action(String[] args, MessageReceivedEvent event) { - if(event.getTextChannel().getName().equals("nsfw-over18")) { + + if(event.getTextChannel().isNSFW()) { Redirection redirect = new Redirection(); boolean success=false; boolean error=false; int errorCp=0; - while(!success&&!error) + while(!success && !error) { try { event.getTextChannel().sendMessage(redirect.get("http://dites.bonjourmadame.fr/random")).queue(); diff --git a/src/main/java/net/Broken/Init.java b/src/main/java/net/Broken/Init.java index 95aa116..0905412 100644 --- a/src/main/java/net/Broken/Init.java +++ b/src/main/java/net/Broken/Init.java @@ -2,6 +2,7 @@ package net.Broken; import net.Broken.Tools.Command.CommandLoader; import net.Broken.Tools.DayListener.DayListener; +import net.Broken.Tools.DayListener.Listeners.DailyMadame; import net.Broken.Tools.DayListener.Listeners.ResetSpam; import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.core.JDA; @@ -83,6 +84,7 @@ public class Init { DayListener dayListener = DayListener.getInstance(); dayListener.addListener(new ResetSpam()); + dayListener.addListener(new DailyMadame()); dayListener.start(); logger.debug("-----------------FIN INITIALISATION-----------------"); diff --git a/src/main/java/net/Broken/Tools/DayListener/Listeners/DailyMadame.java b/src/main/java/net/Broken/Tools/DayListener/Listeners/DailyMadame.java new file mode 100644 index 0000000..f824270 --- /dev/null +++ b/src/main/java/net/Broken/Tools/DayListener/Listeners/DailyMadame.java @@ -0,0 +1,39 @@ +package net.Broken.Tools.DayListener.Listeners; + +import net.Broken.MainBot; +import net.Broken.Tools.DayListener.NewDayListener; +import net.Broken.Tools.Redirection; +import net.dv8tion.jda.core.entities.TextChannel; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; + +public class DailyMadame implements NewDayListener{ + Logger logger = LogManager.getLogger(); + @Override + public void onNewDay() { + Redirection redirect = new Redirection(); + boolean success=false; + boolean error=false; + int errorCp=0; + TextChannel chanel = MainBot.jda.getTextChannelsByName("nsfw-over18", true).get(0); + while(!success && !error) + { + try { + chanel.sendMessage("Le Daily Madame mes petits cochons :kissing_heart:\n" + redirect.get("http://dites.bonjourmadame.fr/random")).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; + + } + + } + } + } +}