<commit_before>var _ = require('underscore')._;

var commands = function(dbot) {
    return {
        '~usage': function(event) {
            var commandName = event.params[1];
            if(_.has(dbot.usage, commandName)) {
                event.reply(dbot.t('usage', {
                    'command': commandName,
                    'usage': dbot.usage[commandName]
                }));
            } else {
                event.reply(dbot.t('no_usage_info', { 
                    'command': commandName 
                }));
            }
        },

        '~help': function(event) {
            var moduleName = event.params[1];
            if(!_.has(dbot.modules, moduleName)) {
                var moduleName = dbot.commands[moduleName].module; 
            }

            if(moduleName && _.has(dbot.config[moduleName], 'help')) {
                var help = dbot.config[moduleName].help;
                event.reply(dbot.t('help_link', {
                    'module': moduleName,
                    'link': help
                }));
            } else {
                if(!moduleName) {
                    moduleName = event.params[1];
                }
                event.reply(dbot.t('no_help', { 'module': moduleName }))
            }
        }
    };
};

exports.fetch = function(dbot) {
    return commands(dbot);
};<commit_msg>adding some extra checks to ~help command to prevent errors<commit_after>var _ = require('underscore')._;

var commands = function(dbot) {
    return {
        '~usage': function(event) {
            var commandName = event.params[1];
            if(_.has(dbot.usage, commandName)) {
                event.reply(dbot.t('usage', {
                    'command': commandName,
                    'usage': dbot.usage[commandName]
                }));
            } else {
                event.reply(dbot.t('no_usage_info', { 
                    'command': commandName 
                }));
            }
        },

        '~help': function(event) {
            var moduleName = event.params[1];
            if(!moduleName) {
                event.reply(dbot.t('usage', {
                    'command': '~help',
                    'usage': '~help [module]'
                }));
                return;
            }
            
            if(!_.has(dbot.modules, moduleName)) {
                if(_.has(dbot.commands, moduleName)) {
                    var moduleName = dbot.commands[moduleName].module; 
                } else {
                    var moduleName = undefined;
                }
            }

            if(moduleName && _.has(dbot.config[moduleName], 'help')) {
                var help = dbot.config[moduleName].help;
                event.reply(dbot.t('help_link', {
                    'module': moduleName,
                    'link': help
                }));
            } else {
                if(!moduleName) {
                    moduleName = event.params[1];
                }
                event.reply(dbot.t('no_help', { 'module': moduleName }))
            }
        }
    };
};

exports.fetch = function(dbot) {
    return commands(dbot);
};
{'fraction_non_alphanumeric': 0.13378033205619413, 'fraction_numerical': 0.0019157088122605363, 'mean_word_length': 1.2346647646219686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7457936', 'n_tokens_mistral': 871, 'n_tokens_neox': 823, 'n_words': 131}