diff --git a/src/main/java/de/construkter/footinfobot/Main.java b/src/main/java/de/construkter/footinfobot/Main.java index dbe5d77..839776f 100644 --- a/src/main/java/de/construkter/footinfobot/Main.java +++ b/src/main/java/de/construkter/footinfobot/Main.java @@ -13,6 +13,7 @@ import de.construkter.footinfobot.modules.news.NewsSender; import de.construkter.footinfobot.modules.notifications.ButtonListener; import de.construkter.footinfobot.modules.notifications.SendPanel; +import de.construkter.footinfobot.modules.versionCheck.VersionChecker; import de.construkter.footinfobot.modules.welcome.JoinListener; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; @@ -47,6 +48,19 @@ public class Main extends ListenerAdapter { public static HashMap> messageCache = new HashMap<>(); public static void main(String[] args) { + // Check if the bot is up to date + boolean upToDate = VersionChecker.isUpToDate(); + if (!upToDate) { + LOGGER.warn("The Bot is not up to date! Please update to the latest version." + + "\nhttps://github.com/construktdev/FootInfoBot"); + } + + try { + Thread.sleep(5000); // Wait for 5 seconds to ensure the user can read the update message + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + // Create a JDA Builder JDABuilder builder = JDABuilder.createDefault(Token.get(), GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS); diff --git a/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionChecker.java b/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionChecker.java new file mode 100644 index 0000000..5ebf815 --- /dev/null +++ b/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionChecker.java @@ -0,0 +1,13 @@ +package de.construkter.footinfobot.modules.versionCheck; + +import de.construkter.footinfobot.Main; + +public class VersionChecker { + + private static final String remoteVersion = VersionFetcher.getRecentVersion(); + + public static boolean isUpToDate() { + String localVersion = Main.VERSION; + return localVersion.equals(remoteVersion); + } +} diff --git a/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionFetcher.java b/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionFetcher.java new file mode 100644 index 0000000..f7e22ab --- /dev/null +++ b/src/main/java/de/construkter/footinfobot/modules/versionCheck/VersionFetcher.java @@ -0,0 +1,24 @@ +package de.construkter.footinfobot.modules.versionCheck; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class VersionFetcher { + public static String getRecentVersion() { + URI uri = URI.create("https://api.construkter.de/projects/footinfobot/version/"); + + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(uri.toURL().openStream(), StandardCharsets.UTF_8))) { + + String firstLine = reader.readLine(); + return firstLine; + } catch (IOException e) { + throw new RuntimeException(e); + } + } +}