Adding manual trigger for dayListener
This commit is contained in:
parent
70bc064cf7
commit
0e08522eaa
67
src/main/java/net/Broken/Commands/DayTrigger.java
Normal file
67
src/main/java/net/Broken/Commands/DayTrigger.java
Normal file
@ -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<Message> messages = new ArrayList<Message>(){{
|
||||
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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user