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

import com.mrpowergamerbr.loritta.commands.CommandBase
import com.mrpowergamerbr.loritta.commands.CommandCategory
import com.mrpowergamerbr.loritta.commands.CommandContext
import net.dv8tion.jda.core.EmbedBuilder
import java.awt.Color
import java.util.*
import javax.script.Invocable
import javax.script.ScriptEngineManager

class EvalCommand : CommandBase() {
	override fun getLabel(): String {
		return "eval"
	}

	override fun getAliases(): List<String> {
		return Arrays.asList("executar")
	}

	override fun getCategory(): CommandCategory {
		return CommandCategory.MAGIC
	}

	override fun onlyOwner(): Boolean {
		return true
	}

	override fun run(context: CommandContext) {
		var javaScript = context.args.joinToString(" ")

		// Agora vamos mudar um pouquinho o nosso código
		javaScript = "function loritta(context) {$javaScript}"

		val engine = ScriptEngineManager().getEngineByName("nashorn") // Iniciar o nashorn
		try {
			engine.eval(javaScript)
			val invocable = engine as Invocable
			val returnedValue = invocable.invokeFunction("loritta", context) // Pegar o valor retornado pelo script

			if (returnedValue != null) {
				context.sendMessage(returnedValue.toString()) // Value of, já que nós não sabemos qual tipo esse objeto é
			}
		} catch (e: Exception) {
			e.printStackTrace()
			val builder = EmbedBuilder()
			builder.setTitle("❌ Ih <NAME>ou! 🤦", "https://youtu.be/G2u8QGY25eU")<commit_msg>:sparkles: | Adicionar stacktrace no "+eval"<commit_after>package com.mrpowergamerbr.loritta.commands.vanilla.magic

import com.mrpowergamerbr.loritta.commands.CommandBase
import com.mrpowergamerbr.loritta.commands.CommandCategory
import com.mrpowergamerbr.loritta.commands.CommandContext
import net.dv8tion.jda.core.EmbedBuilder
import org.apache.commons.lang3.exception.ExceptionUtils
import java.awt.Color
import java.util.*
import java.util.concurrent.ExecutionException
import javax.script.Invocable
import javax.script.ScriptEngineManager

class EvalCommand : CommandBase() {
	override fun getLabel(): String {
		return "eval"
	}

	override fun getAliases(): List<String> {
		return Arrays.asList("executar")
	}

	override fun getCategory(): CommandCategory {
		return CommandCategory.MAGIC
	}

	override fun onlyOwner(): Boolean {
		return true
	}

	override fun run(context: CommandContext) {
		var javaScript = context.args.joinToString(" ")

		// Agora vamos mudar um pouquinho o nosso código
		javaScript = "function loritta(context) {$javaScript}"

		val engine = ScriptEngineManager().getEngineByName("nashorn") // Iniciar o nashorn
		try {
			engine.eval(javaScript)
			val invocable = engine as Invocable
			val returnedValue = invocable.invokeFunction("loritta", context) // Pegar o valor retornado pelo script

			if (returnedValue != null) {
				context.sendMessage(returnedValue.toString()) // Value of, já que nós não sabemos qual tipo esse objeto é
			}
		} catch (e: Exception) {
			val builder = EmbedBuilder()
			builder.setTitle("❌ Ih Serjão Sujou! 🤦", "https://youtu.be/G2u8QGY25eU")
			var description = "Irineu, você não sabe e nem eu!"
			if (e is ExecutionException) {
				description = "A thread que executava este comando agora está nos céus... *+angel* (Provavelmente seu script atingiu o limite máximo de memória utilizada!)"
			} else {
				val message = e.cause?.message
				if (e != null && e.cause != null && message != null) {
					description = message.trim { it <= ' ' }
				} else if (e != null) {
					description = ExceptionUtils.getStackTrace(e).substring(0, Math.min(1000, ExceptionUtils.getStackTrace(e).length))
				}
			}
			builder.setDescription("```$description```")
{'fraction_non_alphanumeric': 0.10913500404203719, 'fraction_numerical': 0.004311506332524926, 'mean_word_length': 4.507418397626113, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '1893754', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1155, 'n_words': 295}