Implemented QUIT and MODE events

This commit is contained in:
Mattias Erming 2014-03-14 16:12:01 +01:00
parent b5571f8fdb
commit 8bedfba27f

View file

@ -271,12 +271,17 @@ function handleEvent(argv) {
name: argv.nick name: argv.nick
}) })
); );
} else {
var irc = network.irc;
if (typeof irc !== "undefined") {
irc.send("TOPIC", argv.args[0]);
}
} }
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
text: "has joined the channel.", text: "join",
type: "join" type: "join"
}) })
); );
@ -298,7 +303,7 @@ function handleEvent(argv) {
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
text: "has left the channel.", text: "part",
type: "part" type: "part"
}) })
); );
@ -308,7 +313,8 @@ function handleEvent(argv) {
case "NICK": case "NICK":
var message = new models.Message({ var message = new models.Message({
user: argv.nick, user: argv.nick,
text: "changed name to " + argv.args[0] text: "changed name to " + argv.args[0],
type: "nick"
}); });
channels.each(function(channel) { channels.each(function(channel) {
@ -330,6 +336,8 @@ function handleEvent(argv) {
}); });
var users = channel.get("users"); var users = channel.get("users");
var messages = channel.get("messages");
if (argv.args[1] == network.get("nick")) { if (argv.args[1] == network.get("nick")) {
users.reset(); users.reset();
} else { } else {
@ -340,16 +348,52 @@ function handleEvent(argv) {
); );
} }
var messages = channel.get("messages");
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.args[1], user: argv.args[1],
text: "was kicked from " + argv.args[0] + " by " + argv.nick, text: "was kicked by " + argv.nick,
type: "kick" type: "kick"
}) })
); );
break; break;
case "QUIT":
var message = new models.Message({
user: argv.nick,
text: "quit",
type: "quit"
});
channels.each(function(channel) {
var user = channel.get("users").findWhere({name: argv.nick});
if (typeof user !== "undefined") {
channel.get("users").remove(user);
channel.get("messages").add(message);
}
});
break;
case "MODE":
var channel = channels.findWhere({name: argv.args[0]});
if (typeof channel === "undefined") {
break;
}
var messages = channel.get("messages");
messages.add(
new models.Message({
user: argv.nick,
text: "sets mode: " + argv.args[1] + " " + argv.args[2],
type: "mode"
})
);
var irc = network.irc;
if (typeof irc !== "undefined") {
irc.send("NAMES", argv.args[0]);
}
break;
case "TOPIC": case "TOPIC":
var channel = channels.findWhere({name: argv.args[0]}); var channel = channels.findWhere({name: argv.args[0]});
var messages = channel.get("messages"); var messages = channel.get("messages");
@ -378,8 +422,8 @@ function handleEvent(argv) {
break; break;
case "rpl_namreply": case "rpl_namreply":
var names = argv.args[3].split(' ');
var channel = network.get("channels").findWhere({name: argv.args[2]}); var channel = network.get("channels").findWhere({name: argv.args[2]});
var users = channel.get("users");
if (typeof channel === "undefined") { if (typeof channel === "undefined") {
channel = channels.add( channel = channels.add(
@ -389,10 +433,13 @@ function handleEvent(argv) {
); );
} }
var users = channel.get("users"); var names = argv.args[3].split(' ');
if (names[0] == network.get("nick")) {
var first = names[0].replace(/^\W/, ''); // Strip mode prefixes
if (first == network.get("nick")) {
users.reset(); users.reset();
} }
for (var i in names) { for (var i in names) {
users.add( users.add(
new models.User({name: names[i]}), { new models.User({name: names[i]}), {
@ -403,7 +450,7 @@ function handleEvent(argv) {
break; break;
case "rpl_endofnames": case "rpl_endofnames":
var channel = network.get("channels").findWhere({name: argv.args[1]}); var channel = channels.findWhere({name: argv.args[1]});
var users = channel.get("users"); var users = channel.get("users");
users.trigger( users.trigger(