From 2af224c90f3f19f9f3e74bfbeadbb65ffc82dd1f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 10 May 2022 11:41:45 -0400 Subject: [PATCH] bugfix: MagicBot needs to autodetect public ip for #status to work. --- src/discord/MagicBot.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 6e1424d4..55df1ee7 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -29,6 +29,8 @@ import org.pmw.tinylog.writers.RollingFileWriter; import javax.security.auth.login.LoginException; import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.EnumSet; import java.util.List; @@ -87,6 +89,23 @@ public class MagicBot extends ListenerAdapter { return; } + if (ConfigManager.MB_PUBLIC_ADDR.getValue().equals("0.0.0.0")) { + + // Autoconfigure IP address for use in worldserver response + // . + Logger.info("AUTOCONFIG PUBLIC IP ADDRESS"); + URL whatismyip = null; + + try { + whatismyip = new URL("http://checkip.amazonaws.com"); + BufferedReader in = null; + in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); + ConfigManager.MB_PUBLIC_ADDR.setValue(in.readLine()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + // Configure Discord essential identifiers discordServerID = Long.parseLong(ConfigManager.MB_MAGICBOT_SERVERID.getValue());