/
module_manager.js
64 lines (57 loc) · 2.04 KB
/
module_manager.js
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
var fs = require('fs');
module.exports = function(app) {
var util = app.util;
return {
type: 'command',
name: 'module',
listAll: function() { return ['reload', 'unload', 'load']; },
getHelp: function() { return {
'reload': '`reload <module-name>` - unload and load the named module',
'load': '`load <module-name>` - load the module specified by the name',
'unload': '`unload <module-name>` - unload the module'
}},
init: function(util, alias) {
alias('reload', 'module.reload');
alias('load', 'module.load');
alias('unload', 'module.unload');
},
listener: function onModuleCmd(line, words, respond, util) {
if (!util.matchesHostname(util.config.get('owner'), line.prefix)) {
respond('you can\'t do this!');
app.events.emit('system.unauthorized', line.nick, words[0]);
return;
}
// the asterisk
var call = this.event.slice(7);
switch (call) {
case 'reload':
var name = words[1];
if (app.modules.hasOwnProperty(name)) {
app.events.emit('module.reload', name);
respond('sent the module.reload event for module ' + name);
}
break;
case 'unload':
var name = words[1];
if (app.modules.hasOwnProperty(name)) {
app.events.emit('module.unload', name);
respond('sent the module.unload event for module ' + name);
}
break;
case 'load':
var name = words[1];
fs.exists(__dirname + '/modules/module-'+name+'.js', function doesModuleExist(yes) {
if (yes) {
app.events.emit('module.new', name);
respond('sent the module.new event for module ' + name);
} else {
respond('the module was not found - see console for details');
console.log('the path ' + __dirname + '/modules/module-' + name +
'.js apparently doesn\'t exist');
}
});
break;
}
}
}
};