<commit_before>package fredboat.command.maintenance;

import fredboat.FredBoat;
import fredboat.commandmeta.abs.Command;
import fredboat.commandmeta.abs.ICommandOwnerRestricted;
import fredboat.util.TextUtils;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import net.dv8tion.jda.JDA;
import net.dv8tion.jda.entities.Guild;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.entities.User;

public class EvalCommand extends Command implements ICommandOwnerRestricted {

    //Thanks Dinos!
    private ScriptEngine engine;

    public EvalCommand() {
        engine = new ScriptEngineManager().getEngineByName("nashorn");
        try {
            engine.eval("var imports = new JavaImporter(java.io, java.lang, java.util);");

        } catch (ScriptException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void onInvoke(Guild guild, TextChannel channel, User author, Message message, String[] args) {
        JDA jda = guild.getJDA();
        String msg = message.getContent();

        channel.sendTyping();

        final String source = message.getRawContent().substring(args[0].length() + 1);

        engine.put("jda", jda);
        engine.put("api", jda);
        engine.put("channel", channel);
        engine.put("author", author);
        engine.put("bot", jda.getSelfInfo());
        engine.put("message", message);
        engine.put("guild", guild);

        ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
        ScheduledFuture<?> future = service.schedule(() -> {

            Object out = null;
            try {
                out = engine.eval(
                        "(function() {"
                        + "with (imports) {\n" + source + "\n}"
                        + "})();");

            } catch (Exception ex) {
                channel.sendMessage("`"+ex.getMessage()+"`");
                return;
            }

            String outputS;
            if (out == null) {
                outputS = ":ok_hand::skin-tone-3:";
            } else if (out.toString().contains("\n")) {
                outputS = "\nEval: ```\n" + out.toString() + "```";
            } else {
                outputS = "\nEval: `" + out.toString() + "`";
            }

            channel.sendMessage("```java\n"+source+"```" + "\n" + outputS);

        }, 0, TimeUnit.MILLISECONDS);

        Thread script = new Thread("Eval") {
            @Override<commit_msg>Added player to the eval<commit_after>package fredboat.command.maintenance;

import fredboat.FredBoat;
import fredboat.audio.PlayerRegistry;
import fredboat.commandmeta.abs.Command;
import fredboat.commandmeta.abs.ICommandOwnerRestricted;
import fredboat.util.TextUtils;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import net.dv8tion.jda.JDA;
import net.dv8tion.jda.entities.Guild;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.entities.User;

public class EvalCommand extends Command implements ICommandOwnerRestricted {

    //Thanks Dinos!
    private ScriptEngine engine;

    public EvalCommand() {
        engine = new ScriptEngineManager().getEngineByName("nashorn");
        try {
            engine.eval("var imports = new JavaImporter(java.io, java.lang, java.util);");

        } catch (ScriptException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void onInvoke(Guild guild, TextChannel channel, User author, Message message, String[] args) {
        JDA jda = guild.getJDA();
        String msg = message.getContent();

        channel.sendTyping();

        final String source = message.getRawContent().substring(args[0].length() + 1);

        engine.put("jda", jda);
        engine.put("api", jda);
        engine.put("channel", channel);
        engine.put("author", author);
        engine.put("bot", jda.getSelfInfo());
        engine.put("message", message);
        engine.put("guild", guild);
        engine.put("player", PlayerRegistry.getExisting(guild));

        ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
        ScheduledFuture<?> future = service.schedule(() -> {

            Object out = null;
            try {
                out = engine.eval(
                        "(function() {"
                        + "with (imports) {\n" + source + "\n}"
                        + "})();");

            } catch (Exception ex) {
                channel.sendMessage("`"+ex.getMessage()+"`");
                return;
            }

            String outputS;
            if (out == null) {
                outputS = ":ok_hand::skin-tone-3:";
            } else if (out.toString().contains("\n")) {
                outputS = "\nEval: ```\n" + out.toString() + "```";
            } else {
                outputS = "\nEval: `" + out.toString() + "`";
            }

            channel.sendMessage("```java\n"+source+"```" + "\n" + outputS);

        }, 0, TimeUnit.MILLISECONDS);

        Thread script = new Thread("Eval") {
            @Override
{'fraction_non_alphanumeric': 0.13514920194309507, 'fraction_numerical': 0.0034698126301179735, 'mean_word_length': 2.4666265784726398, 'pattern_counts': {'":': 2, '<': 5, '<?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': '4738264', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1605, 'n_words': 319}