From 154eac28d10e64eca64ee4ad4fa234e6e0b33ccf Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 25 Jun 2024 12:32:06 +0100 Subject: [PATCH] add ping command --- .../bat/command/impl/PingCommand.java | 36 +++++++++++++++++++ .../bat/service/CommandService.java | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/cc/fascinated/bat/command/impl/PingCommand.java diff --git a/src/main/java/cc/fascinated/bat/command/impl/PingCommand.java b/src/main/java/cc/fascinated/bat/command/impl/PingCommand.java new file mode 100644 index 0000000..047657a --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/impl/PingCommand.java @@ -0,0 +1,36 @@ +package cc.fascinated.bat.command.impl; + +import cc.fascinated.bat.command.BatCommand; +import cc.fascinated.bat.model.BatGuild; +import cc.fascinated.bat.model.BatUser; +import cc.fascinated.bat.service.DiscordService; +import lombok.NonNull; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.internal.interactions.CommandDataImpl; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +public class PingCommand extends BatCommand { + + public PingCommand() { + super("ping"); + super.setDescription("Gets the ping of the bot"); + super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription())); + } + + @Override + public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction) { + long time = System.currentTimeMillis(); + interaction.reply("Pinging...").queue(response -> { + response.editOriginal(("Gateway response time: `%sms`\nAPI response time `%sms`").formatted( + DiscordService.JDA.getGatewayPing(), + System.currentTimeMillis() - time + )).queue(); + }); + } +} diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 3955212..3d715e4 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -2,6 +2,7 @@ package cc.fascinated.bat.service; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.impl.PingCommand; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand; import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand; @@ -50,12 +51,15 @@ public class CommandService extends ListenerAdapter { this.userService = userService; DiscordService.JDA.addEventListener(this); + // todo: auto register commands + // Guild commands registerCommand(context.getBean(UserFeedCommand.class)); registerCommand(context.getBean(NumberOneFeedCommand.class)); // Global commands registerCommand(context.getBean(ScoreSaberCommand.class)); + registerCommand(context.getBean(PingCommand.class)); registerSlashCommands(); // Register all slash commands }