Skip to content

Commit

Permalink
Fix #307 by limiting motd to 100 characters a line
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Mar 17, 2024
1 parent 55fb22b commit ce81962
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ce81962

Please sign in to comment.