use of gnu.trove.impl.unmodifiable.TUnmodifiableLongSet in project MantaroBot by Mantaro.
the class ShardedMantaro method startUpdaters.
private void startUpdaters() {
Async.task("Carbonitex post task", carbonitex::handle, 30, TimeUnit.MINUTES);
if (config.dbotsorgToken != null) {
Async.task("dbots.org update thread", () -> {
try {
long count = MantaroBot.getInstance().getGuildCache().size();
int[] shards = MantaroBot.getInstance().getShardList().stream().mapToInt(shard -> (int) shard.getGuildCache().size()).toArray();
discordBotsAPI.postStats(shards);
log.debug("Updated server count ({}) for discordbots.org", count);
} catch (Exception ignored) {
}
}, 1, TimeUnit.HOURS);
Async.task("discordbots.org upvotes task", () -> {
if (config.dbotsorgToken == null)
return;
try {
Request request = new Request.Builder().url("https://discordbots.org/api/bots/213466096718708737/votes?onlyids=1").addHeader("Authorization", config.dbotsorgToken).build();
Response r = Utils.httpClient.newCall(request).execute();
ResponseBody body = r.body();
if (body == null)
return;
// It's definitely String.
@SuppressWarnings("unchecked") List<String> upvoters = objectMapper.readValue(body.string(), List.class);
List<Long> upvotersLong = upvoters.stream().map(Long::parseLong).distinct().collect(Collectors.toList());
TLongSet set = new TLongHashSet();
set.addAll(upvotersLong);
discordBotsUpvoters = new TUnmodifiableLongSet(set);
r.close();
} catch (Exception ignored) {
}
}, 5, TimeUnit.MINUTES);
} else {
log.warn("discordbots.org token not set in config, cannot start posting stats!");
}
String dbotsToken = config.dbotsToken;
if (dbotsToken != null) {
Async.task("bots.discord.pw update Thread", () -> {
try {
long count = MantaroBot.getInstance().getGuildCache().size();
RequestBody body = RequestBody.create(JSON, new JSONObject().put("server_count", count).toString());
Request request = new Request.Builder().url("https://bots.discord.pw/api/bots/213466096718708737/stats").addHeader("User-Agent", MantaroInfo.USER_AGENT).addHeader("Authorization", dbotsToken).addHeader("Content-Type", "application/json").post(body).build();
Utils.httpClient.newCall(request).execute().close();
log.debug("Updated server count for bots.discord.pw");
} catch (Exception ignored) {
}
}, 1, TimeUnit.HOURS);
}
for (MantaroShard shard : getShards()) {
shard.updateStatus();
}
}
Aggregations