package moe.oko.Kiafumi.command.utility; import moe.oko.Kiafumi.Kiafumi; import moe.oko.Kiafumi.command.CommandClass; import moe.oko.Kiafumi.util.CommandInfo; import moe.oko.Kiafumi.util.CommandType; import moe.oko.Kiafumi.util.EmbedUI; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Random; import static moe.oko.Kiafumi.util.LoggingManager.slashLog; /** * Helpful Ping Command * @author Kay */ public class PingCommand extends CommandClass { //Always true, ping cmd is EXISTENTIAL @Override public boolean isEnabled() { return true; } @Override public String getName() { return "Ping"; } @Override public void newCommand(String name, SlashCommandInteractionEvent e) { if ("ping".equals(name.toLowerCase(Locale.ROOT))) { slashLog(e); e.deferReply().queue(); long sentMs = e.getTimeCreated().toInstant().toEpochMilli(); long recMs = System.currentTimeMillis(); long ping = recMs - sentMs; EmbedBuilder eb = new EmbedBuilder() .setColor(EmbedUI.INFO) .setTitle(getComedy()) .setDescription("Pong! " + ping + "ms") .setFooter(EmbedUI.BRAND) .setTimestamp(ZonedDateTime.now()); e.getHook().sendMessageEmbeds(eb.build()).queue(); } } private String getComedy() { Random r = new Random(); return Kiafumi.instance.config.getPingResponses().get(r.nextInt(Kiafumi.instance.config.getPingResponses().size())); } @Override public List getSlashCommandInfo() { List si = new ArrayList<>(); CommandInfo ci = new CommandInfo("ping", "Returns bot latency with a twist!", CommandType.COMMAND); si.add(ci); return si; } }