diff --git a/src/main/java/net/Broken/Commands/DayTrigger.java b/src/main/java/net/Broken/Commands/DayTrigger.java new file mode 100644 index 0000000..b2cdd3b --- /dev/null +++ b/src/main/java/net/Broken/Commands/DayTrigger.java @@ -0,0 +1,67 @@ +package net.Broken.Commands; + +import net.Broken.Commande; +import net.Broken.MainBot; +import net.Broken.Tools.DayListener.DayListener; +import net.Broken.Tools.EmbedMessageUtils; +import net.Broken.Tools.MessageTimeOut; +import net.Broken.Tools.PrivateMessage; +import net.dv8tion.jda.core.Permission; +import net.dv8tion.jda.core.entities.ChannelType; +import net.dv8tion.jda.core.entities.Message; +import net.dv8tion.jda.core.events.message.MessageReceivedEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; + +public class DayTrigger implements Commande{ + Logger logger = LogManager.getLogger(); + + @Override + public boolean called(String[] args, MessageReceivedEvent event) { + return false; + } + + @Override + public void action(String[] args, MessageReceivedEvent event) { + if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ + DayListener.getInstance().trigger(); + event.getMessage().delete().queue(); + } + else{ + logger.warn("Not admin! DENY!"); + if(!event.isFromType(ChannelType.PRIVATE)){ + Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getError("Vous n'avez pas l'autorisation de faire ça!")).complete(); + List messages = new ArrayList(){{ + add(message); + add(event.getMessage()); + }}; + new MessageTimeOut(messages, MainBot.messageTimeOut).start(); + } + else{ + PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getError("Vous n'avez pas l'autorisation de faire ça!"),logger); + } + + + + } + + } + + @Override + public String help(String[] args) { + return null; + } + + @Override + public void executed(boolean success, MessageReceivedEvent event) { + + } + + @Override + public boolean isPrivateUsable() { + return true; + } +} diff --git a/src/main/java/net/Broken/Tools/DayListener/DayListener.java b/src/main/java/net/Broken/Tools/DayListener/DayListener.java index 19b5c0c..cee9c9a 100644 --- a/src/main/java/net/Broken/Tools/DayListener/DayListener.java +++ b/src/main/java/net/Broken/Tools/DayListener/DayListener.java @@ -16,7 +16,7 @@ public class DayListener extends Thread { private DayListener() { calendar = new GregorianCalendar(); - previousDay = 0; + previousDay = calendar.get(GregorianCalendar.DAY_OF_MONTH); } private static DayListener INSTANCE = new DayListener(); @@ -30,6 +30,12 @@ public class DayListener extends Thread { listeners.add(listener); } + public void trigger(){ + for(NewDayListener listener : listeners){ + listener.onNewDay(); + } + } + @Override public void run() { @@ -38,13 +44,11 @@ public class DayListener extends Thread { if(calendar.get(GregorianCalendar.DAY_OF_MONTH) != previousDay) { LogManager.getLogger().info("New day triggered!"); - for(NewDayListener listener : listeners){ - listener.onNewDay(); - } + trigger(); previousDay = calendar.get(GregorianCalendar.DAY_OF_MONTH); } try { - sleep(7200000); + sleep(1800000); } catch (InterruptedException e) { LogManager.getLogger().catching(e); }