Skip to content

Commit

Permalink
[BUG] ServerStatus Command not replying back
Browse files Browse the repository at this point in the history
Changed the way the Server Status Command works, instead of sending a message, it now replies to the command.

The Refresh button still replies with "Success" once it edits the original reply.
  • Loading branch information
KuryKat committed Feb 27, 2023
1 parent 1db5b02 commit 05adf66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public void onReady(@NotNull ReadyEvent event) {
@Override
public void onButtonInteraction(ButtonInteractionEvent event) {
if (event.getComponentId().equals("refreshbtn")) {
ServerStatusSlashCommand.runStatusCommand(minecraftHelper, event.getChannel(), event.getMessage());
event.reply("Success").setEphemeral(true).queue();
event.getMessage().editMessageEmbeds(ServerStatusSlashCommand.runStatusCommand(minecraftHelper)).queue();
event.reply("Success!").setEphemeral(true).queue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import me.hypherionmc.sdlinklib.discord.BotController;
import me.hypherionmc.sdlinklib.discord.slashcommands.ServerStatusSlashCommand;
import me.hypherionmc.sdlinklib.services.helpers.IMinecraftHelper;
import net.dv8tion.jda.api.interactions.components.buttons.Button;

public class ServerStatusCommand extends BaseCommand {

Expand All @@ -43,7 +44,8 @@ public ServerStatusCommand(BotController controller) {

@Override
protected void execute(CommandEvent event) {
ServerStatusSlashCommand.runStatusCommand(minecraftHelper, event.getChannel(), null);
Button refreshButton = Button.danger("refreshbtn", "Refresh");
event.getChannel().sendMessageEmbeds(ServerStatusSlashCommand.runStatusCommand(minecraftHelper)).addActionRow(refreshButton).queue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import me.hypherionmc.sdlinklib.services.helpers.IMinecraftHelper;
import me.hypherionmc.sdlinklib.utils.SystemUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
Expand All @@ -55,11 +54,11 @@ public ServerStatusSlashCommand(BotController controller) {

@Override
protected void execute(SlashCommandEvent event) {
runStatusCommand(minecraftHelper, event.getChannel(), null);
event.reply("Success").setEphemeral(true).queue();
Button refreshButton = Button.danger("refreshbtn", "Refresh");
event.replyEmbeds(runStatusCommand(minecraftHelper)).addActionRow(refreshButton).queue();
}

public static void runStatusCommand(IMinecraftHelper minecraftHelper, MessageChannel channel, Message message) {
public static MessageEmbed runStatusCommand(IMinecraftHelper minecraftHelper) {
SystemInfo systemInfo = new SystemInfo();
HardwareAbstractionLayer hal = systemInfo.getHardware();
CentralProcessor cpu = hal.getProcessor();
Expand All @@ -83,7 +82,8 @@ public static void runStatusCommand(IMinecraftHelper minecraftHelper, MessageCha
.append(" free of ")
.append(SystemUtils.byteToHuman(hal.getMemory().getTotal()))
.append("```\r\n");
} catch (Exception e) {}
} catch (Exception e) {
}

stringBuilder
.append("**OS:**\r\n```\r\n")
Expand Down Expand Up @@ -114,7 +114,9 @@ public static void runStatusCommand(IMinecraftHelper minecraftHelper, MessageCha

stringBuilder
.append("**Players Online:**\r\n```\r\n")
.append(minecraftHelper.getOnlinePlayerCount() + "/" + minecraftHelper.getMaxPlayerCount())
.append(minecraftHelper.getOnlinePlayerCount())
.append("/")
.append(minecraftHelper.getMaxPlayerCount())
.append("```\r\n");

stringBuilder
Expand All @@ -124,12 +126,6 @@ public static void runStatusCommand(IMinecraftHelper minecraftHelper, MessageCha

builder.setDescription(stringBuilder.toString());

Button refreshButton = Button.danger("refreshbtn", "Refresh");

if (message != null) {
message.editMessageEmbeds(builder.build()).queue();
} else {
channel.sendMessageEmbeds(builder.build()).addActionRow(refreshButton).queue();
}
return builder.build();
}
}

0 comments on commit 05adf66

Please sign in to comment.