forked from GitHub/dbot
Hot-loading now works. Fuck yeah!
This commit is contained in:
parent
e31cb1beb7
commit
3a36ee1894
@ -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.reloadModules();
|
||||
dbot.say(dbot.admin, 'Reloaded.');
|
||||
},
|
||||
|
||||
'say': function(data, params) {
|
||||
|
4
run.js
4
run.js
@ -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));
|
||||
|
||||
|
10
snippets.js
10
snippets.js
@ -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 ***/
|
||||
|
Loading…
Reference in New Issue
Block a user