mirror of
				https://github.com/reality/dbot.git
				synced 2025-11-04 06:07:31 +01:00 
			
		
		
		
	status command and some basic error storing in module load [#198]
This commit is contained in:
		
							parent
							
								
									c77cb09f87
								
							
						
					
					
						commit
						045ff8b9f8
					
				@ -102,6 +102,21 @@ var commands = function(dbot) {
 | 
			
		||||
            }.bind(this));
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        'status': function(event) {
 | 
			
		||||
            var moduleName = event.params[1];
 | 
			
		||||
            if(_.has(dbot.status, moduleName)) {
 | 
			
		||||
                var status = dbot.status[moduleName];
 | 
			
		||||
                if(status === true) {
 | 
			
		||||
                    event.reply(moduleName + ' status: Shit looks good.');
 | 
			
		||||
                } else {
 | 
			
		||||
                    event.reply(moduleName + ' status: Failed to load: ' + status); 
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                event.reply('Either that module wasn\'t on the roster or shit is totally fucked.');
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        // Reload DB, translations and modules.
 | 
			
		||||
        'reload': function(event) {
 | 
			
		||||
            dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
 | 
			
		||||
@ -125,7 +140,11 @@ var commands = function(dbot) {
 | 
			
		||||
            if(!_.include(dbot.config.moduleNames, moduleName)) {
 | 
			
		||||
                dbot.config.moduleNames.push(moduleName);
 | 
			
		||||
                dbot.reloadModules();
 | 
			
		||||
                event.reply(dbot.t('load_module', {'moduleName': moduleName}));
 | 
			
		||||
                if(dbot.status[moduleName] === true) {
 | 
			
		||||
                    event.reply(dbot.t('load_module', {'moduleName': moduleName}));
 | 
			
		||||
                } else {
 | 
			
		||||
                    event.reply('Failed to load ' + moduleName + '. See \'status ' + moduleName + '\'.');
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                if(moduleName == 'web') {
 | 
			
		||||
                    event.reply(dbot.t('already_loaded_web'));
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								run.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								run.js
									
									
									
									
									
								
							@ -5,7 +5,6 @@ var fs = require('fs'),
 | 
			
		||||
require('./snippets');
 | 
			
		||||
 | 
			
		||||
var DBot = function(timers) {
 | 
			
		||||
    
 | 
			
		||||
    // Load DB
 | 
			
		||||
    var rawDB;
 | 
			
		||||
    try {
 | 
			
		||||
@ -55,6 +54,7 @@ var DBot = function(timers) {
 | 
			
		||||
 | 
			
		||||
    // Initialise run-time resources
 | 
			
		||||
    this.usage = {};
 | 
			
		||||
    this.status = {};
 | 
			
		||||
    this.sessionData = {};
 | 
			
		||||
    this.timers = timers.create();
 | 
			
		||||
 | 
			
		||||
@ -119,6 +119,7 @@ DBot.prototype.reloadModules = function() {
 | 
			
		||||
 | 
			
		||||
    this.rawModules = [];
 | 
			
		||||
    this.pages = {};
 | 
			
		||||
    this.status = {};
 | 
			
		||||
    this.modules = {};
 | 
			
		||||
    this.commands = {};
 | 
			
		||||
    this.api = {};
 | 
			
		||||
@ -151,6 +152,7 @@ DBot.prototype.reloadModules = function() {
 | 
			
		||||
    this.instance.removeListeners();
 | 
			
		||||
 | 
			
		||||
    moduleNames.each(function(name) {
 | 
			
		||||
        this.status[name] = true;
 | 
			
		||||
        var moduleDir = './modules/' + name + '/';
 | 
			
		||||
        var cacheKey = require.resolve(moduleDir + name);
 | 
			
		||||
        delete require.cache[cacheKey];
 | 
			
		||||
@ -172,7 +174,13 @@ DBot.prototype.reloadModules = function() {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                var defaultConfig = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8'));
 | 
			
		||||
                var defaultConfig = fs.readFileSync(moduleDir + 'config.json', 'utf-8');
 | 
			
		||||
                try {
 | 
			
		||||
                    defaultConfig = JSON.parse(defaultConfig);
 | 
			
		||||
                } catch(err) { // syntax error
 | 
			
		||||
                    this.status[name] = 'Error parsing config: ' + err + ' ' + err.stack.split('\n')[2].trim();
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                config = _.defaults(config, defaultConfig);
 | 
			
		||||
            } catch(err) {
 | 
			
		||||
                // Invalid or no config data
 | 
			
		||||
@ -188,7 +196,7 @@ DBot.prototype.reloadModules = function() {
 | 
			
		||||
                }, [], this);
 | 
			
		||||
 | 
			
		||||
                if(unmetDependencies.length != 0) {
 | 
			
		||||
                    throw new Error("Dependencies not met: " + unmetDependencies);
 | 
			
		||||
                    this.status[name] = 'Dependencies not met: ' + unmetDependencies;
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@ -265,6 +273,7 @@ DBot.prototype.reloadModules = function() {
 | 
			
		||||
            this.modules[module.name] = module;
 | 
			
		||||
        } catch(err) {
 | 
			
		||||
            console.log(this.t('module_load_error', {'moduleName': name}));
 | 
			
		||||
            this.status[name] = err + ' - ' + err.stack.split('\n')[1].trim();
 | 
			
		||||
            if(this.config.debugMode) {
 | 
			
		||||
                console.log('MODULE ERROR (' + name + '): ' + err.stack );
 | 
			
		||||
            } else {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user