Search in sources :

Example 1 with RedisController

use of stream.flarebot.flarebot.database.RedisController 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();
    }
}
Also used : WebSocketListener(stream.flarebot.flarebot.ws.WebSocketListener) Metrics(stream.flarebot.flarebot.metrics.Metrics) VoiceChannelCleanup(stream.flarebot.flarebot.tasks.VoiceChannelCleanup) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) ShardUtils(stream.flarebot.flarebot.util.ShardUtils) GsonBuilder(com.google.gson.GsonBuilder) Map(java.util.Map) DataInterceptor(stream.flarebot.flarebot.web.DataInterceptor) Request(okhttp3.Request) PlayerCache(stream.flarebot.flarebot.objects.PlayerCache) WebUtils(stream.flarebot.flarebot.util.WebUtils) Set(java.util.Set) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException) PlayerListener(stream.flarebot.flarebot.audio.PlayerListener) DefaultShardManagerBuilder(net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder) WebhookClient(net.dv8tion.jda.webhook.WebhookClient) ZipOutputStream(java.util.zip.ZipOutputStream) Row(com.datastax.driver.core.Row) TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildCountAnalytics(stream.flarebot.flarebot.analytics.GuildCountAnalytics) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) MigrationHandler(stream.flarebot.flarebot.util.MigrationHandler) ShardManager(net.dv8tion.jda.bot.sharding.ShardManager) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Scheduler(stream.flarebot.flarebot.scheduler.Scheduler) ApiRoute(stream.flarebot.flarebot.api.ApiRoute) ApiRequester(stream.flarebot.flarebot.api.ApiRequester) Properties(java.util.Properties) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RestAction(net.dv8tion.jda.core.requests.RestAction) InputStreamReader(java.io.InputStreamReader) ApiFactory(stream.flarebot.flarebot.web.ApiFactory) File(java.io.File) Guild(net.dv8tion.jda.core.entities.Guild) WebhookClientBuilder(net.dv8tion.jda.webhook.WebhookClientBuilder) OkHttpClient(okhttp3.OkHttpClient) CassandraController(stream.flarebot.flarebot.database.CassandraController) ChronoUnit(java.time.temporal.ChronoUnit) Paths(java.nio.file.Paths) ConnectionPool(okhttp3.ConnectionPool) BufferedReader(java.io.BufferedReader) NativeAudioSendFactory(com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory) JsonObject(com.google.gson.JsonObject) ScheduledFuture(java.util.concurrent.ScheduledFuture) FlareBotTask(stream.flarebot.flarebot.scheduler.FlareBotTask) URLDecoder(java.net.URLDecoder) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) SelfUser(net.dv8tion.jda.core.entities.SelfUser) RedisController(stream.flarebot.flarebot.database.RedisController) JSONObject(org.json.JSONObject) Permission(net.dv8tion.jda.core.Permission) Gson(com.google.gson.Gson) WebSocketFactory(stream.flarebot.flarebot.ws.WebSocketFactory) JDA(net.dv8tion.jda.core.JDA) ZipEntry(java.util.zip.ZipEntry) ActivityAnalytics(stream.flarebot.flarebot.analytics.ActivityAnalytics) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) QueueListener(stream.flarebot.flarebot.music.QueueListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) List(java.util.List) LocalDate(java.time.LocalDate) stream.flarebot.flarebot.commands(stream.flarebot.flarebot.commands) UnknownBindingException(com.arsenarsen.lavaplayerbridge.libraries.UnknownBindingException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LibraryFactory(com.arsenarsen.lavaplayerbridge.libraries.LibraryFactory) RequestBody(okhttp3.RequestBody) JsonElement(com.google.gson.JsonElement) ResultSet(com.datastax.driver.core.ResultSet) FutureAction(stream.flarebot.flarebot.scheduler.FutureAction) Constants(stream.flarebot.flarebot.util.Constants) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) Sentry(io.sentry.Sentry) Nonnull(javax.annotation.Nonnull) JSONConfig(io.github.binaryoverload.JSONConfig) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) SentryClient(io.sentry.SentryClient) Game(net.dv8tion.jda.core.entities.Game) DateTime(org.joda.time.DateTime) FileInputStream(java.io.FileInputStream) AnalyticsHandler(stream.flarebot.flarebot.analytics.AnalyticsHandler) NINOListener(stream.flarebot.flarebot.mod.nino.NINOListener) TimeUnit(java.util.concurrent.TimeUnit) Level(ch.qos.logback.classic.Level) GuildAnalytics(stream.flarebot.flarebot.analytics.GuildAnalytics) JDAMultiShard(com.arsenarsen.lavaplayerbridge.utils.JDAMultiShard) Spark(spark.Spark) JSONArray(org.json.JSONArray) CassandraController(stream.flarebot.flarebot.database.CassandraController) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Logger(org.slf4j.Logger) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException) IOException(java.io.IOException) UnknownBindingException(com.arsenarsen.lavaplayerbridge.libraries.UnknownBindingException) JsonElement(com.google.gson.JsonElement) RedisController(stream.flarebot.flarebot.database.RedisController) JSONConfig(io.github.binaryoverload.JSONConfig) SentryClient(io.sentry.SentryClient) File(java.io.File)

Aggregations

Level (ch.qos.logback.classic.Level)1 PlayerManager (com.arsenarsen.lavaplayerbridge.PlayerManager)1 LibraryFactory (com.arsenarsen.lavaplayerbridge.libraries.LibraryFactory)1 UnknownBindingException (com.arsenarsen.lavaplayerbridge.libraries.UnknownBindingException)1 JDAMultiShard (com.arsenarsen.lavaplayerbridge.utils.JDAMultiShard)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 NativeAudioSendFactory (com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory)1 JSONConfig (io.github.binaryoverload.JSONConfig)1 Sentry (io.sentry.Sentry)1 SentryClient (io.sentry.SentryClient)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1