Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/de/construkter/footinfobot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,19 @@ public class Main extends ListenerAdapter {
public static HashMap<User, List<Message>> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading