From 0eeea570c1d72594cfdb777c3be33245d58aa786 Mon Sep 17 00:00:00 2001 From: Chew Date: Mon, 1 Jun 2020 15:45:43 -0500 Subject: [PATCH] Command conversion #3: Ping Command --- src/main/java/pw/chew/Chewbotcca/Main.java | 4 ++- .../commands/about/PingCommand.java | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pw/chew/Chewbotcca/commands/about/PingCommand.java diff --git a/src/main/java/pw/chew/Chewbotcca/Main.java b/src/main/java/pw/chew/Chewbotcca/Main.java index c31207dc..e16be0ce 100644 --- a/src/main/java/pw/chew/Chewbotcca/Main.java +++ b/src/main/java/pw/chew/Chewbotcca/Main.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import pw.chew.Chewbotcca.commands.about.HelpCommand; import pw.chew.Chewbotcca.commands.about.InviteCommand; +import pw.chew.Chewbotcca.commands.about.PingCommand; import javax.security.auth.login.LoginException; import java.io.FileInputStream; @@ -39,7 +40,8 @@ public static void main(String[] args) throws LoginException, IOException { client.addCommands( // About Module new HelpCommand(), - new InviteCommand() + new InviteCommand(), + new PingCommand() ); // Register listeners diff --git a/src/main/java/pw/chew/Chewbotcca/commands/about/PingCommand.java b/src/main/java/pw/chew/Chewbotcca/commands/about/PingCommand.java new file mode 100644 index 00000000..74589eb7 --- /dev/null +++ b/src/main/java/pw/chew/Chewbotcca/commands/about/PingCommand.java @@ -0,0 +1,26 @@ +package pw.chew.Chewbotcca.commands.about; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; + +public class PingCommand extends Command { + + public PingCommand() { + this.name = "ping"; + this.help = "Ping the bot"; + this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; + this.guildOnly = false; + } + + @Override + protected void execute(CommandEvent commandEvent) { + long time = commandEvent.getMessage().getTimeCreated().toInstant().toEpochMilli(); + commandEvent.getChannel().sendMessage(new EmbedBuilder().setDescription("Checking ping..").build()).queue((msg) -> { + EmbedBuilder eb = new EmbedBuilder().setDescription("Ping is " + (msg.getTimeCreated().toInstant().toEpochMilli() - time) + "ms"); + msg.editMessage(eb.build()).queue(); + }); + commandEvent.getChannel().getLatestMessageId(); + } +} \ No newline at end of file