mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
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) {
|
'reload': function(data, params) {
|
||||||
dbot.say(dbot.admin, 'Reloading DB.');
|
|
||||||
try {
|
|
||||||
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||||
} catch(err) {
|
dbot.reloadModules();
|
||||||
dbot.say(dbot.admin, 'DB reload failed.');
|
dbot.say(dbot.admin, 'Reloaded.');
|
||||||
} finally {
|
|
||||||
dbot.say(dbot.admin, 'DB Reload successful.');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'say': function(data, params) {
|
'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 = jsbot.createJSBot(this.name, 'elara.ivixor.net', 6667, this, function() {
|
||||||
this.instance.join('#realitest');
|
this.instance.join('#realitest');
|
||||||
this.instance.join('#42');
|
|
||||||
this.instance.join('#itonlygetsworse');
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.moduleNames = dModules;
|
this.moduleNames = dModules;
|
||||||
@ -39,6 +37,8 @@ DBot.prototype.reloadModules = function() {
|
|||||||
this.modules = [];
|
this.modules = [];
|
||||||
|
|
||||||
this.moduleNames.each(function(name) {
|
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));
|
this.rawModules.push(require('./modules/' + name));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
10
snippets.js
10
snippets.js
@ -1,3 +1,5 @@
|
|||||||
|
/*** Array ***/
|
||||||
|
|
||||||
Array.prototype.random = function() {
|
Array.prototype.random = function() {
|
||||||
return this[Math.floor((Math.random()*this.length))];
|
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++) {
|
for(var i=0;i<this.length;i++) {
|
||||||
collect.push(fun(this[i]));
|
collect.push(fun(this[i]));
|
||||||
}
|
}
|
||||||
|
return collect;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.include = function(value) {
|
Array.prototype.include = function(value) {
|
||||||
var includes = false;
|
|
||||||
for(var i=0;i<this.length;i++) {
|
for(var i=0;i<this.length;i++) {
|
||||||
if(this[i] == value) {
|
if(this[i] == value) {
|
||||||
includes = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return includes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** String ***/
|
/*** String ***/
|
||||||
|
Loading…
Reference in New Issue
Block a user