<commit_before>import fs from "fs";
import walk from "walk-sync";
import inquirer from "inquirer";

const descriptionsToPathsMap = {};
const pluginQuestions = [];

const questions = [
    {
        type: "input",
        name: "TELEGRAM_TOKEN",
        message: "What's the bot token?",
        validate: token => /\d+:\w+/.test(token) ? true : "Please insert a valid token. You can get one from @BotFather."
    },
    {
        type: "checkbox",
        name: "activePlugins",
        message: "What plugins would you like to enable?",
        // Find every file in the plugins folder.
        choices: walk(`${__dirname}/plugins`)
            // Use only .js files.
            .filter(item => /\.js$/i.test(item))
            .map(path => {
                // Remove the extension.
                path = path.replace(/\.js$/i, "");
                let plugin;

                try {
                    plugin = require(`${__dirname}/plugins/${path}`, false).default.plugin;
                } catch (e) {
                    return {
                        name: ` ${path}.js`,
                        disabled: e.message
                    };
                }

                const string = " " + plugin.name + (plugin.description ? ` - ${plugin.description}` : "");
                descriptionsToPathsMap[string] = path;

                if (plugin.needs && plugin.needs.config) {
                    // Iterate through the plugins.needs.config object
                    Object.keys(plugin.needs.config)
                        .map(key => ({
                            name: key,
                            description: plugin.needs.config[key]
                        }))
                        // Map every requirement to an Inquirer.js option
                        .map(item => ({
                            type: "input",
                            name: item.name,
                            message: `${plugin.name} needs: "${item.description}"`,
                            // Ask the question only if:
                            when: answers => (answers.activePlugins.indexOf(string) !== -1) && (Object.keys(answers).indexOf(item.name) === -1)
                            //               /* the plugin is enabled                    */ and/* this parameter hasn't already been asked   */
                        }))
                        // Remove duplicates
                        .filter(item => !pluginQuestions.some(q => q.name === item.name))
                        .forEach(item => pluginQuestions.push(item));
                }

                return {name: string};
            })
    },
    {
        type: "input",
        name: "globalAdmins",
        message: "Enter the list of global admins as an array of user IDs (eg. [1111, 1234])",
        filter: JSON.parse,
        validate: array => {
            try {
                if (array.every(ID => /\d+/.test(ID)))
                    return true;
            } catch (e) {
                console.log(e);
            }
            return "Please insert an array of user IDs.";
        }
    },
    ...pluginQuestions,
    {
        type: "list",
        name: "loggingLevel",
        message: "What logging level is to be used?",
        choices: [
            "error",<commit_msg>Remove debug statement in installer<commit_after>import fs from "fs";
import walk from "walk-sync";
import inquirer from "inquirer";

const descriptionsToPathsMap = {};
const pluginQuestions = [];

const questions = [
    {
        type: "input",
        name: "TELEGRAM_TOKEN",
        message: "What's the bot token?",
        validate: token => /\d+:\w+/.test(token) ? true : "Please insert a valid token. You can get one from @BotFather."
    },
    {
        type: "checkbox",
        name: "activePlugins",
        message: "What plugins would you like to enable?",
        // Find every file in the plugins folder.
        choices: walk(`${__dirname}/plugins`)
            // Use only .js files.
            .filter(item => /\.js$/i.test(item))
            .map(path => {
                // Remove the extension.
                path = path.replace(/\.js$/i, "");
                let plugin;

                try {
                    plugin = require(`${__dirname}/plugins/${path}`, false).default.plugin;
                } catch (e) {
                    return {
                        name: ` ${path}.js`,
                        disabled: e.message
                    };
                }

                const string = " " + plugin.name + (plugin.description ? ` - ${plugin.description}` : "");
                descriptionsToPathsMap[string] = path;

                if (plugin.needs && plugin.needs.config) {
                    // Iterate through the plugins.needs.config object
                    Object.keys(plugin.needs.config)
                        .map(key => ({
                            name: key,
                            description: plugin.needs.config[key]
                        }))
                        // Map every requirement to an Inquirer.js option
                        .map(item => ({
                            type: "input",
                            name: item.name,
                            message: `${plugin.name} needs: "${item.description}"`,
                            // Ask the question only if:
                            when: answers => (answers.activePlugins.indexOf(string) !== -1) && (Object.keys(answers).indexOf(item.name) === -1)
                            //               /* the plugin is enabled                    */ and/* this parameter hasn't already been asked   */
                        }))
                        // Remove duplicates
                        .filter(item => !pluginQuestions.some(q => q.name === item.name))
                        .forEach(item => pluginQuestions.push(item));
                }

                return {name: string};
            })
    },
    {
        type: "input",
        name: "globalAdmins",
        message: "Enter the list of global admins as an array of user IDs (eg. [1111, 1234])",
        filter: JSON.parse,
        validate: array => {
            try {
                if (array.every(ID => /\d+/.test(ID)))
                    return true;
            } catch (e) {
            }
            return "Please insert an array of user IDs.";
        }
    },
    ...pluginQuestions,
    {
        type: "list",
        name: "loggingLevel",
        message: "What logging level is to be used?",
        choices: [
            "error",
{'fraction_non_alphanumeric': 0.12507626601586333, 'fraction_numerical': 0.003050640634533252, 'mean_word_length': 1.1776818332779808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7173429', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1570, 'n_words': 430}