-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchannels.js
More file actions
39 lines (33 loc) · 923 Bytes
/
channels.js
File metadata and controls
39 lines (33 loc) · 923 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
39
var replies = require('./replies').codes;
var chanels = {
"#default": {
topic: "no topic",
users: []
},
"#random": {
topic: "no topic",
users: []
},
"#general": {
topic: "no topic",
users: []
}
};
exports.list = chanels;
exports.channelNames = function() { return Object.keys(chanels); }
exports.joinOrCreate = function(nick, channel){
if(chanels[channel] == undefined){
chanels[channel] = {}
chanels[channel].topic = "New channel";
chanels[channel].users = [];
}
chanels[channel].users.push(nick);
}
exports.leave = function(nick, channel){
if (chanels[channel] == undefined)
return replies.ERR_NOSUCHCHANNEL;
if (chanels[channel].users.indexOf(nick) < 0)
return replies.ERR_NOSUCHNICK;
chanels[channel].users.splice(chanels[channel].users.indexOf(nick),1)
return false;
}