<commit_before>package com.mrpowergamerbr.loritta.threads

import com.mrpowergamerbr.loritta.Loritta
import com.mrpowergamerbr.loritta.listeners.DiscordListener
import com.mrpowergamerbr.loritta.listeners.EventLogListener
import com.mrpowergamerbr.loritta.listeners.MusicMessageListener
import com.mrpowergamerbr.loritta.listeners.UpdateTimeListener
import com.mrpowergamerbr.loritta.utils.loritta
import com.mrpowergamerbr.loritta.utils.lorittaShards
import net.dv8tion.jda.core.AccountType
import net.dv8tion.jda.core.JDABuilder
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

class ShardReviverThread : Thread("Shard Reviver") {
	override fun run() {
		super.run()

		while (true) {
			try {
				checkAndReviveDeadShards()
			} catch (e: Exception) {
				e.printStackTrace()
			}
			Thread.sleep(1000)
		}
	}

	fun checkAndReviveDeadShards() {
		for (shard in lorittaShards.shards) {
			val lastUpdate = lorittaShards.lastJdaEventTime.getOrDefault(shard, System.currentTimeMillis())

			val seconds = (System.currentTimeMillis() - lastUpdate) / 1000

			if (seconds >= 3) {
				println("[!] Shard ${shard.shardInfo.shardId} não recebeu update a mais de 3s! ~  ${seconds}s")
			}
		}

		val deadShards = lorittaShards.shards.filter {
			val lastUpdate = lorittaShards.lastJdaEventTime.getOrDefault(it, System.currentTimeMillis())

			System.currentTimeMillis() - lastUpdate > 10000
		}

		if (deadShards.isNotEmpty()) {
			val okHttpBuilder = OkHttpClient.Builder()
					.connectTimeout(60, TimeUnit.SECONDS)
					.readTimeout(60, TimeUnit.SECONDS)
					.writeTimeout(60, TimeUnit.SECONDS)

			val discordListener = DiscordListener(loritta); // Vamos usar a mesma instância para todas as shards
			val eventLogListener = EventLogListener(loritta); // Vamos usar a mesma instância para todas as shards
			val updateTimeListener = UpdateTimeListener(loritta);
			val messageListener = MusicMessageListener(loritta)

			for (deadShard in deadShards) {
				println("Reiniciando shard ${deadShard.shardInfo.shardId}")
				val guild = loritta.lorittaShards.getGuildById("297732013006389252")
				if (guild != null) {
					val textChannel = guild.getTextChannelById("297732013006389252")
					textChannel.sendMessage("Shard ${deadShard.shardInfo.shardId} demorou mais de 10 segundos para responder... \uD83D\uDE22 ~ Irei reiniciar esta shard (e torcer para que não dê problema novamente! \uD83D\uDE47)").complete()
				}
				val shardId = deadShard.shardInfo.shardId

				lorittaShards.shards.remove(deadShard)
				lorittaShards.lastJdaEventTime.remove(deadShard)

				deadShard.shutdownNow()

				val shard = JDABuilder(AccountType.BOT)
						.useSharding(shardId, Loritta.config.shards)
						.setToken(Loritta.config.clientToken)
						.setHttpClientBuilder(okHttpBuilder)
						.setCorePoolSize(8)
						.buildBlocking()

				if (!loritta.isMusicOnly) {
					shard.addEventListener(updateTimeListener)
					shard.addEventListener(discordListener)
					shard.addEventListener(eventLogListener)
				} else {
					shard.addEventListener(updateTimeListener)
					shard.addEventListener(messageListener)
				}

				lorittaShards.shards.add(deadShard)
			}
		}
	}
}<commit_msg>:bug: | ...adicionar a guild criada e não a deadShard<commit_after>package com.mrpowergamerbr.loritta.threads

import com.mrpowergamerbr.loritta.Loritta
import com.mrpowergamerbr.loritta.listeners.DiscordListener
import com.mrpowergamerbr.loritta.listeners.EventLogListener
import com.mrpowergamerbr.loritta.listeners.MusicMessageListener
import com.mrpowergamerbr.loritta.listeners.UpdateTimeListener
import com.mrpowergamerbr.loritta.utils.loritta
import com.mrpowergamerbr.loritta.utils.lorittaShards
import net.dv8tion.jda.core.AccountType
import net.dv8tion.jda.core.JDABuilder
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

class ShardReviverThread : Thread("Shard Reviver") {
	override fun run() {
		super.run()

		while (true) {
			try {
				checkAndReviveDeadShards()
			} catch (e: Exception) {
				e.printStackTrace()
			}
			Thread.sleep(1000)
		}
	}

	fun checkAndReviveDeadShards() {
		for (shard in lorittaShards.shards) {
			val lastUpdate = lorittaShards.lastJdaEventTime.getOrDefault(shard, System.currentTimeMillis())

			val seconds = (System.currentTimeMillis() - lastUpdate) / 1000

			if (seconds >= 3) {
				println("[!] Shard ${shard.shardInfo.shardId} não recebeu update a mais de 3s! ~  ${seconds}s")
			}
		}

		val deadShards = lorittaShards.shards.filter {
			val lastUpdate = lorittaShards.lastJdaEventTime.getOrDefault(it, System.currentTimeMillis())

			System.currentTimeMillis() - lastUpdate > 10000
		}

		if (deadShards.isNotEmpty()) {
			val okHttpBuilder = OkHttpClient.Builder()
					.connectTimeout(60, TimeUnit.SECONDS)
					.readTimeout(60, TimeUnit.SECONDS)
					.writeTimeout(60, TimeUnit.SECONDS)

			val discordListener = DiscordListener(loritta); // Vamos usar a mesma instância para todas as shards
			val eventLogListener = EventLogListener(loritta); // Vamos usar a mesma instância para todas as shards
			val updateTimeListener = UpdateTimeListener(loritta);
			val messageListener = MusicMessageListener(loritta)

			for (deadShard in deadShards) {
				println("Reiniciando shard ${deadShard.shardInfo.shardId}")
				val guild = loritta.lorittaShards.getGuildById("297732013006389252")
				if (guild != null) {
					val textChannel = guild.getTextChannelById("297732013006389252")
					textChannel.sendMessage("Shard ${deadShard.shardInfo.shardId} demorou mais de 10 segundos para responder... \uD83D\uDE22 ~ Irei reiniciar esta shard (e torcer para que não dê problema novamente! \uD83D\uDE47)").complete()
				}
				val shardId = deadShard.shardInfo.shardId

				lorittaShards.shards.remove(deadShard)
				lorittaShards.lastJdaEventTime.remove(deadShard)

				deadShard.shutdownNow()

				val shard = JDABuilder(AccountType.BOT)
						.useSharding(shardId, Loritta.config.shards)
						.setToken(Loritta.config.clientToken)
						.setHttpClientBuilder(okHttpBuilder)
						.setCorePoolSize(8)
						.buildBlocking()

				if (!loritta.isMusicOnly) {
					shard.addEventListener(updateTimeListener)
					shard.addEventListener(discordListener)
					shard.addEventListener(eventLogListener)
				} else {
					shard.addEventListener(updateTimeListener)
					shard.addEventListener(messageListener)
				}

				lorittaShards.shards.add(shard)
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.0982532751091703, 'fraction_numerical': 0.022145976294447912, 'mean_word_length': 4.439355385920272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7151925', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2140, 'n_words': 376}