module on destroy and process exit

This commit is contained in:
Luke Slater 2011-09-14 17:24:32 +01:00
parent a63d350b50
commit 36874ac3e6
2 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,12 @@ var webInterface = function(dbot) {
});
app.listen(1337);
return { };
return {
'onDestroy': function() {
process.exit();
}
};
};
exports.fetch = function(dbot) {

7
run.js
View File

@ -17,6 +17,7 @@ var DBot = function(dModules, timers) {
this.instance.join('#fail');
this.instance.join('#42');
this.instance.join('#itonlygetsworse');
this.instance.join('#plur');
}.bind(this));
this.moduleNames = dModules;
@ -42,6 +43,12 @@ DBot.prototype.reloadModules = function() {
require.cache[path] = undefined;
require('./snippets');
this.modules.each(function(module) {
if(module.onDestroy) {
module.onDestroy();
}
});
this.moduleNames.each(function(name) {
var cacheKey = require.resolve('./modules/' + name);
require.cache[cacheKey] = undefined; // TODO: snippet to remove element properly