Search in sources :

Example 1 with VoiceChannelCleanup

use of stream.flarebot.flarebot.tasks.VoiceChannelCleanup in project FlareBot by FlareBot.

the class FlareBot method runTasks.

public void runTasks() {
    new FlareBotTask("FixThatStatus") {

        @Override
        public void run() {
            if (!UPDATING.get())
                setStatus("_help | _invite");
        }
    }.repeat(10, TimeUnit.SECONDS.toMillis(32));
    new FlareBotTask("PostDbotsData") {

        @Override
        public void run() {
            if (config.getString("botlists.discordBots").isPresent()) {
                postToBotList(config.getString("botlists.discordBots").get(), String.format("https://bots.discord.pw/api/bots/%s/stats", Getters.getSelfUser().getId()));
            }
        }
    }.repeat(10, TimeUnit.MINUTES.toMillis(10));
    new FlareBotTask("PostBotlistData") {

        @Override
        public void run() {
            if (config.getString("botlists.botlist").isPresent()) {
                postToBotList(config.getString("botlists.botlist").get(), String.format("https://discordbots.org/api/bots/%s/stats", Getters.getSelfUser().getId()));
            }
        }
    }.repeat(10, TimeUnit.MINUTES.toMillis(10));
    new FlareBotTask("PostCarbonData") {

        @Override
        public void run() {
            if (config.getString("botlists.carbon").isPresent()) {
                try {
                    WebUtils.post("https://www.carbonitex.net/discord/data/botdata.php", WebUtils.APPLICATION_JSON, new JSONObject().put("key", config.getString("botlists.carbon").get()).put("servercount", Getters.getGuildCache().size()).put("shardcount", Getters.getShards().size()).toString());
                } catch (IOException e) {
                    LOGGER.error("Failed to update carbon!", e);
                }
            }
        }
    }.repeat(10, TimeUnit.MINUTES.toMillis(10));
    new FlareBotTask("spam" + System.currentTimeMillis()) {

        @Override
        public void run() {
            events.getSpamMap().clear();
        }
    }.repeat(TimeUnit.SECONDS.toMillis(3), TimeUnit.SECONDS.toMillis(3));
    new FlareBotTask("DeadShard-Checker") {

        @Override
        public void run() {
            if (getImportantWebhook() == null) {
                LOGGER.warn("No webhook for the important-log channel! Due to this the dead shard checker has been disabled!");
                cancel();
                return;
            }
            if (Getters.getShards().size() == 1) {
                LOGGER.warn("Single sharded bot, the DeadShard-Checker has been disabled!");
                cancel();
                return;
            }
            // 10 mins without an event... this son bitch is dead.
            if (Getters.getShards().stream().anyMatch(shard -> ShardUtils.isDead(shard, TimeUnit.MINUTES.toMillis(10)))) {
                Getters.getShards().stream().filter(shard -> ShardUtils.isDead(shard, TimeUnit.MINUTES.toMillis(10))).forEach(shard -> {
                    getImportantWebhook().send("Restarting " + ShardUtils.getShardId(shard) + " as it seems to be dead.");
                    shardManager.restart(ShardUtils.getShardId(shard));
                });
            }
            Set<Integer> deadShards = Getters.getShards().stream().filter(ShardUtils::isDead).map(ShardUtils::getShardId).collect(Collectors.toSet());
            if (!deadShards.isEmpty()) {
                getImportantWebhook().send("Found " + deadShards.size() + " possibly dead shards! Shards: " + deadShards.toString());
            }
        }
    }.repeat(TimeUnit.MINUTES.toMillis(10), TimeUnit.MINUTES.toMillis(5));
    new FlareBotTask("GuildCleanup") {

        @Override
        public void run() {
            FlareBotManager.instance().getGuilds().cleanUp();
        }
    }.repeat(0, TimeUnit.SECONDS.toMillis(30));
    /*new FlareBotTask("ActivityChecker") {
            @Override
            public void run() {
                for (VoiceChannel channel : Getters.getConnectedVoiceChannel()) {
                    if (channel.getMembers().stream().anyMatch(member -> !member.getUser().isBot()
                            && !member.getUser().isFake())
                            && !getMusicManager().getPlayer(channel.getGuild().getId()).getPlaylist().isEmpty()
                            && !getMusicManager().getPlayer(channel.getGuild().getId()).getPaused()) {
                        manager.getLastActive().remove(channel.getGuild().getIdLong());
                        return;
                    }
                    if (manager.getLastActive().containsKey(channel.getGuild().getIdLong())
                            && System.currentTimeMillis() >= (manager.getLastActive().get(channel.getGuild().getIdLong())
                            + TimeUnit.MINUTES.toMillis(10)))
                        channel.getGuild().getAudioManager().closeAudioConnection();
                }
            }
        }.repeat(10_000, 10_000);*/
    new VoiceChannelCleanup("VoiceChannelCleanup");
}
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) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) Set(java.util.Set) ResultSet(com.datastax.driver.core.ResultSet) JSONObject(org.json.JSONObject) VoiceChannelCleanup(stream.flarebot.flarebot.tasks.VoiceChannelCleanup) IOException(java.io.IOException) FlareBotTask(stream.flarebot.flarebot.scheduler.FlareBotTask) ShardUtils(stream.flarebot.flarebot.util.ShardUtils)

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