<commit_before>/* eslint-disable no-unused-vars */

const util = require('util');

const { Command } = require('discord-akairo');
const Logger = require('../../util/Logger');

const data = {};

class EvalCommand extends Command {
    constructor() {
        super('eval', {
            aliases: ['eval', 'e'],
            category: 'eval',
            args: [
                {
                    id: 'code',
                    match: 'content'
                }
            ]
        });

        this.lastResult = null;
    }

    async exec(message, { code, input }) {
        if (!code) {
            Logger.error('No code provided to evaluate.');
            await message.delete();
            return;
        }

        const evaled = {};
        const logs = [];

        const token = this.client.token.split('').join('[^]{0,2}');
        const rev = this.client.token.split('').reverse().join('[^]{0,2}');
        const tokenRegex = new RegExp(`${token}|${rev}`, 'g');

        const print = (...a) => {
            const cleaned = a.map(o => {
                o = util.inspect(o, { depth: 0 });
                return o.replace(tokenRegex, '[TOKEN]');
            });

            if (!evaled.output) {
                logs.push(...cleaned);
                return;
            }

            evaled.output += evaled.output.endsWith('\n') ? cleaned.join(' ') : `\n${cleaned.join(' ')}`;
            const title = evaled.errored ? '☠\u2000**Error**' : '📤\u2000**Output**';

            if (evaled.output.length + code.length > 1900) evaled.output = 'Output too long.';
            message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `${title}${cb}js`,
                evaled.output,
                cb
            ]);
        };

        const msg = message;
        const mesg = message;
        const client = this.client;
        const bot = this.client;
        const lastResult = this.lastResult;
        const cb = '```';

        try {
            let output = eval(code);
            if (output instanceof Promise) output = await output;
            this.lastResult = output;

            output = util.inspect(output, { depth: 0 });
            output = `${logs.join('\n')}\n${logs.length && output === 'undefined' ? '' : output}`;
            output = output.replace(tokenRegex, '[TOKEN]');

            if (output.length + code.length > 1900) output = 'Output too long.';

            await message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `📤\u2000**Output**${cb}js`,
                output,
                cb
            ]);

            evaled.errored = false;
            evaled.output = output;
        } catch (err) {
            Logger.error('Evaluation errored.');
            Logger.stacktrace(err);

            let e = err.toString();
            e = `${logs.join('\n')}\n${logs.length && e === 'undefined' ? '' : e}`;
            e = e.replace(tokenRegex, '[TOKEN]');

            await message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `☠\u2000**Error**${cb}js`,
                e,
                cb
            ]);

            evaled.errored = true;
            evaled.output = e;
        }
    }
}

module.exports = EvalCommand;
<commit_msg>Move data obj onto command<commit_after>/* eslint-disable no-unused-vars */

const util = require('util');

const { Command } = require('discord-akairo');
const Logger = require('../../util/Logger');

class EvalCommand extends Command {
    constructor() {
        super('eval', {
            aliases: ['eval', 'e'],
            category: 'eval',
            args: [
                {
                    id: 'code',
                    match: 'content'
                }
            ]
        });

        this.data = {};
        this.lastResult = null;
    }

    async exec(message, { code, input }) {
        if (!code) {
            Logger.error('No code provided to evaluate.');
            await message.delete();
            return;
        }

        const evaled = {};
        const logs = [];

        const token = this.client.token.split('').join('[^]{0,2}');
        const rev = this.client.token.split('').reverse().join('[^]{0,2}');
        const tokenRegex = new RegExp(`${token}|${rev}`, 'g');

        const print = (...a) => {
            const cleaned = a.map(o => {
                o = util.inspect(o, { depth: 0 });
                return o.replace(tokenRegex, '[TOKEN]');
            });

            if (!evaled.output) {
                logs.push(...cleaned);
                return;
            }

            evaled.output += evaled.output.endsWith('\n') ? cleaned.join(' ') : `\n${cleaned.join(' ')}`;
            const title = evaled.errored ? '☠\u2000**Error**' : '📤\u2000**Output**';

            if (evaled.output.length + code.length > 1900) evaled.output = 'Output too long.';
            message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `${title}${cb}js`,
                evaled.output,
                cb
            ]);
        };

        const msg = message;
        const mesg = message;
        const client = this.client;
        const bot = this.client;
        const lastResult = this.lastResult;
        const data = this.data;
        const cb = '```';

        try {
            let output = eval(code);
            if (output instanceof Promise) output = await output;
            this.lastResult = output;

            output = util.inspect(output, { depth: 0 });
            output = `${logs.join('\n')}\n${logs.length && output === 'undefined' ? '' : output}`;
            output = output.replace(tokenRegex, '[TOKEN]');

            if (output.length + code.length > 1900) output = 'Output too long.';

            await message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `📤\u2000**Output**${cb}js`,
                output,
                cb
            ]);

            evaled.errored = false;
            evaled.output = output;
        } catch (err) {
            Logger.error('Evaluation errored.');
            Logger.stacktrace(err);

            let e = err.toString();
            e = `${logs.join('\n')}\n${logs.length && e === 'undefined' ? '' : e}`;
            e = e.replace(tokenRegex, '[TOKEN]');

            await message.edit([
                `📥\u2000**Input**${cb}js`,
                input || code,
                cb,
                `☠\u2000**Error**${cb}js`,
                e,
                cb
            ]);

            evaled.errored = true;
            evaled.output = e;
        }
    }
}

module.exports = EvalCommand;

{'fraction_non_alphanumeric': 0.16382451537676723, 'fraction_numerical': 0.012243113248797552, 'mean_word_length': 1.3475880944235374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6686985', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1916, 'n_words': 400}