change stuff and fix

This commit is contained in:
Chayapak 2023-08-01 16:59:36 +07:00
parent a1e02ce21d
commit 8f5d1cc6ae
2 changed files with 10 additions and 7 deletions

View file

@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import land.chipmunk.chayapak.chomens_bot.plugins.ConsolePlugin;
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
import land.chipmunk.chayapak.chomens_bot.util.LoggerUtilities;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
@ -12,7 +13,6 @@ 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;
@ -91,16 +91,18 @@ public class Main {
boolean reachable;
try {
reachable = InetAddress.getByName(config.backup.address).isReachable(5000);
} catch (IOException e) {
HttpUtilities.getRequest(new URL(config.backup.address));
reachable = true;
} catch (Exception e) {
reachable = false;
}
if (!reachable) {
if (!reachable && !alreadyStarted) {
LoggerUtilities.info("Main instance is down! Starting backup instance");
initializeBots();
} else if (alreadyStarted) {
} else if (reachable && alreadyStarted) {
System.exit(1);
}
}, 0, 1, TimeUnit.MINUTES);

View file

@ -17,10 +17,11 @@ internetCheck:
# if the address is reachable it will not start the bot
# if the address is not reachable then it will start the bot
#
# if the bot has already been started and address is back up it will stop the bot (using System.exit(1))
# if the bot has already been started and the address is back up it
# will stop the bot (using System.exit(1))
backup:
enabled: false
address: '192.168.1.169'
address: 'https://fard.sex/check'
discord:
enabled: false