use of stream.flarebot.flarebot.database.CassandraController in project FlareBot by FlareBot.
the class FlareBot method main.
public static void main(String[] args) {
Spark.port(8080);
try {
File file = new File("config.json");
if (!file.exists() && !file.createNewFile())
throw new IllegalStateException("Can't create config file!");
try {
config = new JSONConfig(new File("config.json"), '.', new char[] { '-', '_', '<', '>', '@' });
} catch (NullPointerException e) {
LOGGER.error("Invalid JSON!", e);
System.exit(1);
}
} catch (IOException e) {
LOGGER.error("Unable to create config.json!", e);
System.exit(1);
}
List<String> required = new ArrayList<>();
required.add("bot.token");
required.add("cassandra.username");
required.add("cassandra.password");
required.add("misc.yt");
required.add("redis.host");
required.add("redis.port");
required.add("redis.password");
required.add("sentry.dsn");
boolean good = true;
for (String req : required) {
if (config.getString(req) != null) {
if (!config.getString(req).isPresent()) {
good = false;
LOGGER.error("Missing required json " + req);
}
} else {
good = false;
LOGGER.error("Missing required json " + req);
}
}
if (!good) {
LOGGER.error("One or more of the required JSON objects where missing. Exiting to prevent problems");
System.exit(1);
}
new CassandraController(config);
new RedisController(config);
FlareBot.youtubeApi = config.getString("misc.yt").get();
if (config.getArray("options").isPresent()) {
for (JsonElement em : config.getArray("options").get()) {
if (em.getAsString() != null) {
if (em.getAsString().equals("tb")) {
FlareBot.testBot = true;
}
if (em.getAsString().equals("debug")) {
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME)).setLevel(Level.DEBUG);
}
}
}
}
SentryClient sentryClient = Sentry.init(config.getString("sentry.dsn").get() + "?stacktrace.app.packages=stream.flarebot.flarebot");
sentryClient.setEnvironment(testBot ? "TestBot" : "Production");
sentryClient.setServerName(testBot ? "Test Server" : "Production Server");
sentryClient.setRelease(GitHandler.getLatestCommitId());
if (!config.getString("misc.apiKey").isPresent() || config.getString("misc.apiKey").get().isEmpty())
apiEnabled = false;
Thread.setDefaultUncaughtExceptionHandler(((t, e) -> LOGGER.error("Uncaught exception in thread " + t, e)));
Thread.currentThread().setUncaughtExceptionHandler(((t, e) -> LOGGER.error("Uncaught exception in thread " + t, e)));
try {
(instance = new FlareBot()).init();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations