3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 03:33:07 +01:00

Hot-loading now works. Fuck yeah!

This commit is contained in:
Luke Slater 2011-08-24 16:15:42 +01:00
parent e31cb1beb7
commit 3a36ee1894
3 changed files with 10 additions and 15 deletions

View File

@ -14,14 +14,9 @@ var adminCommands = function(dbot) {
},
'reload': function(data, params) {
dbot.say(dbot.admin, 'Reloading DB.');
try {
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
} catch(err) {
dbot.say(dbot.admin, 'DB reload failed.');
} finally {
dbot.say(dbot.admin, 'DB Reload successful.');
}
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
dbot.reloadModules();
dbot.say(dbot.admin, 'Reloaded.');
},
'say': function(data, params) {

4
run.js
View File

@ -13,8 +13,6 @@ var DBot = function(dModules, quotes) {
this.instance = jsbot.createJSBot(this.name, 'elara.ivixor.net', 6667, this, function() {
this.instance.join('#realitest');
this.instance.join('#42');
this.instance.join('#itonlygetsworse');
}.bind(this));
this.moduleNames = dModules;
@ -39,6 +37,8 @@ DBot.prototype.reloadModules = function() {
this.modules = [];
this.moduleNames.each(function(name) {
var cacheKey = require.resolve('./modules/' + name);
require.cache[cacheKey] = undefined; // TODO: snippet to remove element properly
this.rawModules.push(require('./modules/' + name));
}.bind(this));

View File

@ -1,3 +1,5 @@
/*** Array ***/
Array.prototype.random = function() {
return this[Math.floor((Math.random()*this.length))];
};
@ -13,18 +15,16 @@ Array.prototype.collect = function(fun) {
for(var i=0;i<this.length;i++) {
collect.push(fun(this[i]));
}
return collect;
};
Array.prototype.include = function(value) {
var includes = false;
for(var i=0;i<this.length;i++) {
if(this[i] == value) {
includes = true;
break;
return true;
}
}
return includes;
return false;
};
/*** String ***/