-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbabbot.js
More file actions
45 lines (33 loc) · 1.04 KB
/
babbot.js
File metadata and controls
45 lines (33 loc) · 1.04 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
'use strict';
var path = require('path'),
fs = require('fs');
var babbot = function () {
var self = this;
self.onMessage = function (platform, argv, state) {
if(argv !== undefined){
if(argv.length >= 1){
var command = argv[0].substr(1),
atIndex = command.indexOf('@');
if (atIndex !== -1) {
command = command.substr(0, atIndex);
}
}
if(argv.length >= 2){
var query = argv.slice(1).join(' ');
}
}
if(command !== undefined){
self.modules.forEach(function (item) {
if (item.commands.indexOf(command) === -1) {
return;
}
item.onCommand(command, query, platform, state);
});
}
}
var modulePath = path.join(__dirname, 'modules');
self.modules = fs.readdirSync(modulePath).map(function (file) {
return require('./modules/' + file);
});
};
module.exports = babbot;