make the server watcher list command look better
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m13s

This commit is contained in:
Lee 2024-07-06 07:35:06 +01:00
parent bbbbce557b
commit 9379ebb33d

@ -13,9 +13,15 @@ import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.apache.catalina.Server;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import xyz.mcutils.models.server.ServerPlatform; import xyz.mcutils.models.server.ServerPlatform;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author Fascinated (fascinated7) * @author Fascinated (fascinated7)
*/ */
@ -29,18 +35,23 @@ public class ListSubCommand extends BatCommand {
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
MinecraftProfile profile = guild.getMinecraftProfile(); MinecraftProfile profile = guild.getMinecraftProfile();
Map<ServerPlatform, List<ServerWatcher>> watchers = new HashMap<>();
for (ServerWatcher server : profile.getServerWatchers()) {
watchers.computeIfAbsent(server.getPlatform(), k -> new ArrayList<>()).add(server);
}
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Server Watcher"); EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Server Watcher");
description.appendLine("Here is a list of all the servers being watched", false); description.appendLine("Here is a list of all the servers being watched", false);
description.emptyLine(); description.emptyLine();
for (ServerWatcher server : profile.getServerWatchers()) {
int platformDefaultPort = server.getPlatform() == ServerPlatform.JAVA ? 25565 : 19132;
String hostname = server.getHostname() + (server.getPort() != platformDefaultPort ? ":" + server.getPort() : "");
description.appendLine("`%s` (%s) - %s".formatted( for (Map.Entry<ServerPlatform, List<ServerWatcher>> entry : watchers.entrySet()) {
hostname, description.appendLine("**%s**".formatted(EnumUtils.getEnumName(entry.getKey())), false);
EnumUtils.getEnumName(server.getPlatform()), for (ServerWatcher server : entry.getValue()) {
server.getChannel().getAsMention() description.appendLine("`%s` - %s".formatted(
), true); server.getHostname(),
server.getChannel().getAsMention()
), true);
}
description.emptyLine();
} }
event.replyEmbeds(EmbedUtils.successEmbed() event.replyEmbeds(EmbedUtils.successEmbed()