Check ENV var before start

This commit is contained in:
Sebastien 2018-12-31 15:08:19 +01:00
parent 96cd3411eb
commit ecd5ed31a3
2 changed files with 63 additions and 2 deletions

View File

@ -113,4 +113,58 @@ public class Init {
} }
public static boolean checkEnv(){
boolean ok = true;
if(System.getenv("PORT") == null){
logger.fatal("Missing PORT ENV variable.");
ok = false;
}
if(System.getenv("DB_URL") == null){
logger.fatal("Missing DB_URL ENV variable.");
ok = false;
}
if(System.getenv("DB_USER") == null){
logger.fatal("Missing DB_USER ENV variable.");
ok = false;
}
if(System.getenv("DB_PWD") == null){
logger.fatal("Missing DB_PWD ENV variable.");
ok = false;
}
if(System.getenv("OAUTH_URL") == null){
logger.fatal("Missing OAUTH_URL ENV variable.");
ok = false;
}
if(System.getenv("DISCORD_TOKEN") == null){
logger.fatal("Missing DISCORD_TOKEN ENV variable.");
ok = false;
}
if(System.getenv("GOOGLE_API_KEY") == null){
logger.fatal("Missing GOOGLE_API_KEY ENV variable.");
ok = false;
}
if(System.getenv("RANDOM_API_KEY") == null){
logger.fatal("Missing GOOGLE_API_KEY ENV variable.");
ok = false;
}
if(System.getenv("LOG_LEVEL") == null){
logger.fatal("Missing LOG_LEVEL ENV variable.");
ok = false;
}
return ok;
}
} }

View File

@ -51,14 +51,19 @@ public class MainBot {
public static void main(String[] args) { public static void main(String[] args) {
if(!Init.checkEnv())
System.exit(1);
logger.info("======================================="); logger.info("=======================================");
logger.info("--------------Starting Bot-------------"); logger.info("--------------Starting Bot-------------");
logger.info("======================================="); logger.info("=======================================");
if(System.getenv("DEV")!= null){ if(System.getenv("DEV")!= null){
dev = Boolean.parseBoolean(System.getenv("DEV")); dev = Boolean.parseBoolean(System.getenv("DEV"));
} }
String token = System.getenv("TOKEN");
String token = System.getenv("DISCORD_TOKEN");
jda = Init.initJda(token); jda = Init.initJda(token);
@ -134,4 +139,6 @@ public class MainBot {
} }
} }
} }