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");
}
Aggregations