Added ping command
This commit is contained in:
parent
d2177c02a4
commit
9f32139085
@ -40,6 +40,7 @@ public class MGZBot {
|
|||||||
commandClientBuilder.addCommand(new EditMessageCommand());
|
commandClientBuilder.addCommand(new EditMessageCommand());
|
||||||
commandClientBuilder.addCommand(new AddReactionToMessageCommand());
|
commandClientBuilder.addCommand(new AddReactionToMessageCommand());
|
||||||
commandClientBuilder.addCommand(new MemberCountCommand());
|
commandClientBuilder.addCommand(new MemberCountCommand());
|
||||||
|
commandClientBuilder.addCommand(new PingCommand());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jda = JDABuilder.createDefault(BotConstants.TOKEN)
|
jda = JDABuilder.createDefault(BotConstants.TOKEN)
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package zone.themcgamer.discordbot.command.impl;
|
||||||
|
|
||||||
|
import com.jagrosh.jdautilities.command.CommandEvent;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import zone.themcgamer.discordbot.command.BaseCommand;
|
||||||
|
import zone.themcgamer.discordbot.guild.Guild;
|
||||||
|
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
||||||
|
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PingCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private static long inputTime;
|
||||||
|
|
||||||
|
public static void setInputTime(long inputTimeLong) {
|
||||||
|
inputTime = inputTimeLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color getColorByPing(long ping) {
|
||||||
|
if (ping < 100)
|
||||||
|
return Color.cyan;
|
||||||
|
if (ping < 400)
|
||||||
|
return Color.green;
|
||||||
|
if (ping < 700)
|
||||||
|
return Color.yellow;
|
||||||
|
if (ping < 1000)
|
||||||
|
return Color.orange;
|
||||||
|
return Color.red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PingCommand() {
|
||||||
|
name = "ping";
|
||||||
|
aliases = new String[]{"latency"};
|
||||||
|
help = "Get the latency of the bot to the guild.";
|
||||||
|
guildOnly = true;
|
||||||
|
guilds = Arrays.asList(Guild.MAIN, Guild.TEAM, Guild.TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(CommandEvent event, List<String> args) {
|
||||||
|
long processing = new Date().getTime() - inputTime;
|
||||||
|
long ping = event.getJDA().getGatewayPing();
|
||||||
|
event.getTextChannel().sendMessage(EmbedUtils.defaultEmbed().setColor(getColorByPing(ping)).setDescription(
|
||||||
|
String.format(":ping_pong: **Pong!**\n\nThe bot took `%s` milliseconds to response.\nIt took `%s` milliseconds to parse the command and the ping is `%s` milliseconds.",
|
||||||
|
processing + ping, processing, ping)
|
||||||
|
).build()).queue();
|
||||||
|
}
|
||||||
|
}
|
@ -35,10 +35,11 @@ public class SuggestCommand extends BaseCommand {
|
|||||||
TextChannel channel = MGZBot.getInstance().getJda().getTextChannelById(BotConstants.SUGGESTIONS);
|
TextChannel channel = MGZBot.getInstance().getJda().getTextChannelById(BotConstants.SUGGESTIONS);
|
||||||
if (channel == null)
|
if (channel == null)
|
||||||
return;
|
return;
|
||||||
|
int charLimit = 120;
|
||||||
String suggestion = args.stream().skip(1).collect(Collectors.joining(" "));
|
String suggestion = args.stream().skip(1).collect(Collectors.joining(" "));
|
||||||
if (suggestion.length() < 120) {
|
if (suggestion.length() < charLimit) {
|
||||||
event.getChannel().sendMessage(EmbedUtils.errorEmbed()
|
event.getChannel().sendMessage(EmbedUtils.errorEmbed()
|
||||||
.appendDescription("Your suggestion is too short. Suggestions must be at least 120 characters.")
|
.appendDescription("Your suggestion is too short. Suggestions must be at least " + charLimit + " characters.")
|
||||||
.build()
|
.build()
|
||||||
).queue();
|
).queue();
|
||||||
return;
|
return;
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package zone.themcgamer.skyblock;
|
package zone.themcgamer.skyblock;
|
||||||
|
|
||||||
|
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock;
|
||||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
|
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
|
||||||
|
import com.bgsoftware.superiorskyblock.api.handlers.GridManager;
|
||||||
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
|
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import zone.themcgamer.core.chat.ChatManager;
|
import zone.themcgamer.core.chat.ChatManager;
|
||||||
|
Reference in New Issue
Block a user