ClaptrapBot/src/main/java/net/Broken/Commandes/PingCommande.java

63 lines
1.9 KiB
Java
Raw Normal View History

2017-03-20 21:01:49 +01:00
package net.Broken.Commandes;
2016-12-08 20:05:23 +01:00
2017-03-20 18:44:53 +01:00
import net.Broken.Commande;
2017-10-16 17:03:17 +02:00
import net.Broken.MainBot;
import net.Broken.Outils.MessageTimeOut;
2017-03-20 21:01:49 +01:00
import net.dv8tion.jda.core.entities.ChannelType;
2017-10-16 17:03:17 +02:00
import net.dv8tion.jda.core.entities.Message;
2016-12-08 20:05:23 +01:00
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
2017-03-20 21:01:49 +01:00
import java.sql.Timestamp;
import java.time.*;
2017-10-16 17:03:17 +02:00
import java.util.ArrayList;
import java.util.List;
2017-03-20 21:01:49 +01:00
2016-12-08 20:05:23 +01:00
/**
* Created by seb65 on 19/10/2016.
*/
public class PingCommande implements Commande {
private String HELP = "`//ping` \n :arrow_right:\t*Le bot vous répondra Pong!*";
@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return true;
}
@Override
public void action(String[] args, MessageReceivedEvent event) {
2017-03-20 21:01:49 +01:00
long receivedTime = Timestamp.valueOf(LocalDateTime.ofInstant(event.getMessage().getCreationTime().toInstant(), ZoneId.systemDefault())).getTime();
if(event.isFromType(ChannelType.PRIVATE))
event.getPrivateChannel().sendMessage(":arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
2017-10-16 17:03:17 +02:00
else {
Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").complete();
List<Message> messages = new ArrayList<Message>(){{
add(rest);
add(event.getMessage());
}};
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
}
2017-09-04 18:36:23 +02:00
LogManager.getLogger().debug("pong");
2016-12-08 20:05:23 +01:00
}
@Override
public String help(String[] args) {
return HELP;
}
@Override
public void executed(boolean success, MessageReceivedEvent event)
{
return;
}
2017-09-05 02:13:27 +02:00
@Override
public boolean isPrivateUsable() {
return true;
}
2016-12-08 20:05:23 +01:00
}