kiafumi/src/main/java/moe/oko/Kiafumi/command/PingCommand.java

80 lines
2.7 KiB
Java
Raw Normal View History

package moe.oko.Kiafumi.command;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;
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 legacyCommand(String[] args, MessageReceivedEvent e, boolean prefix) {
if(!prefix) { return; }
if ("ping".equals(args[0].toLowerCase())) {
long sentMs = e.getMessage().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.getChannel().sendMessageEmbeds(eb.build()).queue();
}
}
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
if ("ping".equals(name.toLowerCase(Locale.ROOT))) {
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<String> getCommandsAsList() {
return null;
}
@Override
public List<CommandInfo> getSlashCommandInfo() {
List<CommandInfo> si = new ArrayList<>();
CommandInfo ci = new CommandInfo("ping", "Returns bot latency with a twist!");
si.add(ci);
return si;
}
}