Search in sources :

Example 1 with Holder

use of br.com.brjdevs.java.utils.holding.objects.Holder in project MantaroBot by Mantaro.

the class MantaroShard method updateServerCount.

public void updateServerCount() {
    Config config = config().get();
    Holder<Integer> guildCount = new Holder<>(jda.getGuilds().size());
    String dbotsToken = config.dbotsToken;
    String dbotsorgToken = config.dbotsorgToken;
    if (dbotsToken != null || dbotsorgToken != null) {
        Async.task("Botlist API update Thread", () -> {
            int newC = jda.getGuilds().size();
            try {
                guildCount.accept(newC);
                if (dbotsToken != null) {
                    log.debug("Successfully posted the botdata to bots.discord.pw: " + Unirest.post("https://bots.discord.pw/api/bots/" + jda.getSelfUser().getId() + "/stats").header("Authorization", dbotsToken).header("Content-Type", "application/json").body(new JSONObject().put("server_count", newC).put("shard_id", getId()).put("shard_count", totalShards).toString()).asString().getBody());
                }
                if (dbotsorgToken != null) {
                    log.debug("Successfully posted the botdata to discordbots.org: " + Unirest.post("https://discordbots.org/api/bots/" + jda.getSelfUser().getId() + "/stats").header("Authorization", dbotsorgToken).header("Content-Type", "application/json").body(new JSONObject().put("server_count", newC).put("shard_id", getId()).put("shard_count", totalShards).toString()).asString().getBody());
                }
            } catch (Exception e) {
                log.warn("An error occurred while posting the botdata to discord lists (DBots/Carbonitex/DBots.org)", e);
            }
        }, 1, TimeUnit.HOURS);
    }
    //Carbon is special now.
    Async.task(new Carbonitex(jda, getId(), getTotalShards()), 30, TimeUnit.MINUTES);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Carbonitex(net.kodehawa.mantarobot.services.Carbonitex) JSONObject(org.json.JSONObject) Config(net.kodehawa.mantarobot.data.Config) Holder(br.com.brjdevs.java.utils.holding.objects.Holder) LoginException(javax.security.auth.login.LoginException) RateLimitedException(net.dv8tion.jda.core.exceptions.RateLimitedException)

Aggregations

Holder (br.com.brjdevs.java.utils.holding.objects.Holder)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LoginException (javax.security.auth.login.LoginException)1 RateLimitedException (net.dv8tion.jda.core.exceptions.RateLimitedException)1 Config (net.kodehawa.mantarobot.data.Config)1 Carbonitex (net.kodehawa.mantarobot.services.Carbonitex)1 JSONObject (org.json.JSONObject)1