forked from martynsmith/node-irc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodulehandler.js
More file actions
98 lines (69 loc) · 1.87 KB
/
modulehandler.js
File metadata and controls
98 lines (69 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var pm = require("./passwordmanager");
exports.ModuleHandler = ModuleHandler;
function ModuleHandler( bot ) {
var self = this;
self.bot = bot;
self.plugins = [
"./modules/quakelive",
"./modules/greeter",
"./modules/pickup",
"./modules/commands",
"./modules/quakelink",
"./modules/spotify",
"./modules/fredrik",
"./modules/qlchat"
];
self.loadedplugins = [];
bot.on('pm', function( from, text ) {
if(text === 'reload') {
self.bot.say( from, "Reloading plugins..." );
self.loadPlugins();
self.bot.say( from, "Done." );
}
});
self.init();
}
ModuleHandler.prototype.printPlugins = function() {
var self = this;
var str = '';
self.loadedplugins.forEach(function (plugin){
str += plugin + " ";
});
return str;
}
ModuleHandler.prototype.init = function() {
var self = this;
self.plugins.forEach(function (plugin){
console.log("Attempting to load: %s", plugin);
var loadedplugin = require( plugin ).init( self.bot );
//self.loadedplugins.push( loadedplugin );
});
}
ModuleHandler.prototype.loadPlugins = function() {
var self = this;
self.bot.removeAllListeners('join');
self.bot.removeAllListeners('pm');
self.bot.removeAllListeners('message');
self.bot.removeAllListeners('topic');
self.bot.addListener('pm', function( from, text ) {
if(text === "reload") {
self.bot.say( from, "Reloading plugins..." );
self.loadPlugins();
self.bot.say( from, "Done." );
}
});
self.plugins.forEach(function (plugin){
var name = require.resolve( plugin );
var cachedModule = require.cache[ name ];
if( cachedModule ) {
for( var i in cachedModule.exports ) {
delete cachedModule.exports[i];
}
delete require.cache[ name ];
}
// reload
var reloadedPlugin = require( plugin ).init( self.bot );
console.log("Reloaded plugin --> %s", plugin);
//self.loadedplugins.push( reloadedPlugin );
});
}