2013-03-05 20:23:02 +00:00
|
|
|
var Rank = require('./rank.js');
|
2013-03-16 21:49:58 +00:00
|
|
|
var Poll = require('./poll.js').Poll;
|
2013-03-05 20:23:02 +00:00
|
|
|
|
2013-03-05 18:51:58 +00:00
|
|
|
function handle(chan, user, msg) {
|
|
|
|
if(msg.indexOf("/me ") == 0)
|
|
|
|
chan.sendMessage(user.name, msg.substring(4), "action");
|
|
|
|
else if(msg.indexOf("/sp ") == 0)
|
|
|
|
chan.sendMessage(user.name, msg.substring(4), "spoiler");
|
2013-03-05 20:23:02 +00:00
|
|
|
else if(msg.indexOf("/kick ") == 0) {
|
|
|
|
handleKick(chan, user, msg.substring(6).split(' '));
|
|
|
|
}
|
2013-03-16 21:49:58 +00:00
|
|
|
else if(msg.indexOf("/poll ") == 0) {
|
|
|
|
handlePoll(chan, user, msg.substring(6));
|
|
|
|
}
|
2013-03-05 20:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleKick(chan, user, args) {
|
|
|
|
if(Rank.hasPermission(user, "kick") && args.length > 0) {
|
|
|
|
var kickee;
|
|
|
|
for(var i = 0; i < chan.users.length; i++) {
|
|
|
|
if(chan.users[i].name == args[0]) {
|
|
|
|
kickee = chan.users[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(kickee) {
|
|
|
|
kickee.socket.disconnect();
|
|
|
|
chan.userLeave(kickee);
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 21:49:58 +00:00
|
|
|
function handlePoll(chan, user, msg) {
|
|
|
|
if(Rank.hasPermission(user, "poll")) {
|
|
|
|
var args = msg.split(',');
|
|
|
|
var title = args[0];
|
|
|
|
args.splice(0, 1);
|
|
|
|
var poll = new Poll(title, args);
|
|
|
|
chan.poll = poll;
|
|
|
|
chan.broadcastPoll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:51:58 +00:00
|
|
|
exports.handle = handle;
|
|
|
|
|