<commit_before>package com.mrpowergamerbr.loritta.commands.vanilla.utils

import com.google.common.math.BigIntegerMath
import com.mrpowergamerbr.loritta.commands.AbstractCommand
import com.mrpowergamerbr.loritta.commands.CommandContext
import com.mrpowergamerbr.loritta.utils.LoriReply
import com.mrpowergamerbr.loritta.utils.locale.LegacyBaseLocale
import net.perfectdreams.loritta.api.commands.CommandCategory
import net.perfectdreams.loritta.utils.Emotes


class AnagramaCommand : AbstractCommand("anagram", listOf("anagrama"), CommandCategory.UTILS) {
	companion object {
		private const val LOCALE_PREFIX = "commands.utils.anagram"
	}

	override fun getUsage(): String {
		return "palavra"
	}

	override fun getDescription(locale: LegacyBaseLocale): String {
		return locale["ANAGRAMA_DESCRIPTION"]
	}

	override fun getExtendedExamples(): Map<String, String> {
		return mapOf("Loritta" to "Cria um anagrama usando a palavra \"Loritta\"",
				"kk eae men" to "Cria um anagrama usando a frase \"kk eae men\"")
	}

	override suspend fun run(context: CommandContext,locale: LegacyBaseLocale) {
		if (context.args.isNotEmpty()) {
			val currentWord = context.args.joinToString(separator = " ")

			var shuffledChars = currentWord.toCharArray().toList()

			while (currentWord.length != 1 && shuffledChars.joinToString("") == currentWord)
				shuffledChars = shuffledChars.shuffled()

			val shuffledWord = shuffledChars.joinToString(separator = "")

			var exp = 1.toBigInteger()
			repeat(shuffledChars.size) {
				exp = exp.multiply(BigIntegerMath.factorial(it))
			}

			val max = BigIntegerMath.factorial(currentWord.length).divide(exp)

			context.reply(
					LoriReply(
							message = context.locale["$LOCALE_PREFIX.result", shuffledWord] + " ${Emotes.LORI_WOW}",
							prefix = "✍"
					),
					LoriReply(
							message = context.locale["$LOCALE_PREFIX.stats", currentWord, max],
							prefix = "\uD83E\uDD13"
					)
			)
		} else {
			this.explain(context)
		}
	}<commit_msg>Corrigir "+anagrama" entrando em loop infinito ao colocar apenas um caractere<commit_after>package com.mrpowergamerbr.loritta.commands.vanilla.utils

import com.google.common.math.BigIntegerMath
import com.mrpowergamerbr.loritta.commands.AbstractCommand
import com.mrpowergamerbr.loritta.commands.CommandContext
import com.mrpowergamerbr.loritta.utils.LoriReply
import com.mrpowergamerbr.loritta.utils.locale.LegacyBaseLocale
import net.perfectdreams.loritta.api.commands.CommandCategory
import net.perfectdreams.loritta.utils.Emotes


class AnagramaCommand : AbstractCommand("anagram", listOf("anagrama"), CommandCategory.UTILS) {
	companion object {
		private const val LOCALE_PREFIX = "commands.utils.anagram"
	}

	override fun getUsage(): String {
		return "palavra"
	}

	override fun getDescription(locale: LegacyBaseLocale): String {
		return locale["ANAGRAMA_DESCRIPTION"]
	}

	override fun getExtendedExamples(): Map<String, String> {
		return mapOf("Loritta" to "Cria um anagrama usando a palavra \"Loritta\"",
				"kk eae men" to "Cria um anagrama usando a frase \"kk eae men\"")
	}

	override suspend fun run(context: CommandContext,locale: LegacyBaseLocale) {
		if (context.args.isNotEmpty()) {
			val currentWord = context.args.joinToString(separator = " ")

			var shuffledChars = currentWord.toCharArray().toList()

			while (shuffledChars.size != 1 && shuffledChars.joinToString("") == currentWord)
				shuffledChars = shuffledChars.shuffled()

			val shuffledWord = shuffledChars.joinToString(separator = "")

			var exp = 1.toBigInteger()
			repeat(shuffledChars.size) {
				exp = exp.multiply(BigIntegerMath.factorial(it))
			}

			val max = BigIntegerMath.factorial(currentWord.length).divide(exp)

			context.reply(
					LoriReply(
							message = context.locale["$LOCALE_PREFIX.result", shuffledWord] + " ${Emotes.LORI_WOW}",
							prefix = "✍"
					),
					LoriReply(
							message = context.locale["$LOCALE_PREFIX.stats", currentWord, max],
							prefix = "\uD83E\uDD13"
					)
			)
		} else {
			this.explain(context)
		}
	}
{'fraction_non_alphanumeric': 0.11504205838693717, 'fraction_numerical': 0.0029688273132112814, 'mean_word_length': 4.545953360768175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1379086', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1301, 'n_words': 248}