backup thingy

This commit is contained in:
ChomeNS
2023-07-30 21:29:35 +07:00
parent fec4f20420
commit dc5a62540b
3 changed files with 46 additions and 0 deletions

View File

@@ -15,6 +15,8 @@ public class Configuration {
public InternetCheck internetCheck = new InternetCheck();
public Backup backup = new Backup();
public String weatherApiKey;
public Core core = new Core();
@@ -35,6 +37,11 @@ public class Configuration {
public String address = "https://sus.red";
}
public static class Backup {
public boolean enabled = false;
public String address = "http://fard.sex/check";
}
public static class Keys {
public String normalKey;
public String ownerKey;

View File

@@ -12,6 +12,7 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import java.io.*;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
@@ -38,6 +39,8 @@ public class Main {
private static Configuration config;
private static boolean alreadyStarted = false;
public static void main(String[] args) throws IOException {
final Path configPath = Path.of("config.yml");
@@ -79,6 +82,33 @@ public class Main {
}
}, 0, 1, TimeUnit.MINUTES);
if (!config.backup.enabled) {
initializeBots();
return;
}
executor.scheduleAtFixedRate(() -> {
boolean reachable;
try {
reachable = InetAddress.getByName(config.backup.address).isReachable(5000);
} catch (IOException e) {
reachable = false;
}
if (!reachable) {
LoggerUtilities.info("Main instance is down! Starting backup instance");
initializeBots();
} else if (alreadyStarted) {
System.exit(1);
}
}, 0, 1, TimeUnit.MINUTES);
}
public static void initializeBots() {
alreadyStarted = true;
Configuration.BotOption[] botsOptions = config.bots;
// idk if these should be here lol, but it is just the discord stuff