{"size": 1273, "ext": "js", "max_stars_repo_path": "src/commands/index.js", "max_stars_repo_name": "MadCow234/ics-bot", "max_stars_repo_stars_event_min_datetime": "2020-02-05T11:07:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-05T11:07:23.000Z", "max_issues_repo_path": "src/commands/index.js", "max_issues_repo_name": "MadCow234/ics-bot", "max_issues_repo_issues_event_min_datetime": "2021-05-11T02:06:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T10:29:53.000Z", "max_forks_repo_path": "src/commands/index.js", "max_forks_repo_name": "MadCow234/ics-bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 34.4054054054, "max_line_length": 122, "alphanum_fraction": 0.6048703849}
import { readdirSync } from 'fs';
import log             from 'winston';

/**
 * Reads the commands directory and returns a list of valid command names.
 *
 * @returns {Promise<[String]>} an list of valid command names
 */
exports.getCommands = async () => {
    try {
        let commandsArray = [];

        // Read the files in this directory
        let commandFiles = await readdirSync(__dirname);

        // Log a warning if the directory is empty or the index.js file is the only one in the directory
        if (commandFiles.length === 0 || (commandFiles.length === 1 && commandFiles[0] === 'index.js')) {
            log.warn(`Could not retrieve commands. Reason: 'No commands have been defined in the /commands/ directory.'`);
            return commandsArray;
        }

        // Create a Discord event listener for each file in this directory
        for (let file of commandFiles) {
            // Skip this file because it is not an event
            if (file === 'index.js') continue;

            let commandName = file.split(".")[0];
            commandsArray.push(commandName.toLowerCase());
        }

        return commandsArray;

    } catch (err) {
        log.error(`[/commands/index.js] Could not retrieve commands. Reason: '${err}'`);
    }
};
