From ce81962f5b1da1fc8ecc261c7b5cb658407e568f Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 17 Mar 2024 10:20:28 +0000 Subject: [PATCH] Fix #307 by limiting motd to 100 characters a line --- .../java/org/geysermc/discordbot/commands/PingCommand.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/geysermc/discordbot/commands/PingCommand.java b/src/main/java/org/geysermc/discordbot/commands/PingCommand.java index 131fb552..19a8272b 100644 --- a/src/main/java/org/geysermc/discordbot/commands/PingCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/PingCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022 GeyserMC. http://geysermc.org + * Copyright (c) 2020-2024 GeyserMC. http://geysermc.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,6 +40,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.geysermc.discordbot.util.BotColors; +import org.geysermc.discordbot.util.BotHelpers; import org.geysermc.discordbot.util.MessageHelper; import org.geysermc.discordbot.util.NetworkUtils; @@ -143,7 +144,7 @@ private MessageEmbed handle(String ip) { MCPingResponse data = MCPing.getPing(options); - javaInfo = "**MOTD:** \n```\n" + data.getDescription().getStrippedText() + "\n```\n" + + javaInfo = "**MOTD:** \n```\n" + BotHelpers.trim(data.getDescription().getStrippedText(), 100) + "\n```\n" + "**Players:** " + (data.getPlayers() == null ? "Unknown" : data.getPlayers().getOnline() + "/" + data.getPlayers().getMax()) + "\n" + "**Version:** " + data.getVersion().getName() + " (" + data.getVersion().getProtocol() + ")"; success = true; @@ -160,7 +161,7 @@ private MessageEmbed handle(String ip) { InetSocketAddress addressToPing = new InetSocketAddress(hostname, bePort); BedrockPong pong = client.ping(addressToPing, 1500, TimeUnit.MILLISECONDS).get(); - bedrockInfo = "**MOTD:** \n```\n" + MCPingUtil.stripColors(pong.getMotd()) + (pong.getSubMotd() != null ? "\n" + MCPingUtil.stripColors(pong.getSubMotd()) : "") + "\n```\n" + + bedrockInfo = "**MOTD:** \n```\n" + BotHelpers.trim(MCPingUtil.stripColors(pong.getMotd()), 100) + (pong.getSubMotd() != null ? "\n" + BotHelpers.trim(MCPingUtil.stripColors(pong.getSubMotd()), 100) : "") + "\n```\n" + "**Players:** " + pong.getPlayerCount() + "/" + pong.getMaximumPlayerCount() + "\n" + "**Version:** " + pong.getVersion() + " (" + pong.getProtocolVersion() + ")"; success = true;