-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcommands.js
More file actions
38 lines (36 loc) · 920 Bytes
/
commands.js
File metadata and controls
38 lines (36 loc) · 920 Bytes
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
var _ = require('underscore');
module.exports = function(myData, io, display){
var commands = {
'\/name (\\w*)': function(matches){
if(matches[1] != 'server'){
myData.name = matches[1];
io.emit('update', myData);
}
},
'\/color (\\w*)': function(matches){
myData.color = matches[1];
io.emit('update', myData);
},
'\/users': function(){
io.emit('getUsers');
},
'\/help': function(){
display.addMessage('Available Commands:\n'+
'/color hexvalue\n'+
'/name newname', 'help', myData.color);
}
};
return function(message){
var res = _.chain(commands)
.pairs()
.find(function(item){
var key = item[0];
var result = new RegExp(key).exec(message);
if(result !== null){
item[1](result);
}
return result !== null;
}).value();
return !!res;
};
};