Added /whois command

This commit is contained in:
Mattias Erming 2014-03-14 14:24:47 +01:00
parent cc4b6cdfe5
commit 5a7a93947f
1 changed files with 50 additions and 13 deletions

View File

@ -167,6 +167,13 @@ function handleInput(input) {
} }
break; break;
case "WHOIS":
var irc = network.irc;
if (typeof irc !== "undefined") {
irc.send(cmd, argv[1] || target.channel.get("name"));
}
break;
default: default:
channel.get("messages").add( channel.get("messages").add(
new models.Message({ new models.Message({
@ -187,16 +194,6 @@ function handleEvent(argv) {
switch (event) { switch (event) {
case "ERROR":
var args = argv.args;
channels.first().get("messages").add(
new models.Message({
text: args[args.length - 1],
type: "error"
})
);
break;
case "PRIVMSG": case "PRIVMSG":
var target = argv.args[0]; var target = argv.args[0];
if (target.charAt(0) != "#") { if (target.charAt(0) != "#") {
@ -229,6 +226,7 @@ function handleEvent(argv) {
text: "notice: " + argv.args[1], text: "notice: " + argv.args[1],
type: "notice" type: "notice"
}); });
channels.each(function(channel) { channels.each(function(channel) {
channel.get("messages").add(message); channel.get("messages").add(message);
}); });
@ -254,6 +252,7 @@ function handleEvent(argv) {
}) })
); );
} }
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
@ -290,6 +289,7 @@ function handleEvent(argv) {
user: argv.nick, user: argv.nick,
text: "changed name to " + argv.args[0] text: "changed name to " + argv.args[0]
}); });
channels.each(function(channel) { channels.each(function(channel) {
var user = channel.get("users").findWhere({name: argv.nick}); var user = channel.get("users").findWhere({name: argv.nick});
if (typeof user !== "undefined") { if (typeof user !== "undefined") {
@ -297,6 +297,7 @@ function handleEvent(argv) {
channel.get("messages").add(message); channel.get("messages").add(message);
} }
}); });
if (argv.nick == network.get("nick")) { if (argv.nick == network.get("nick")) {
network.set("nick", argv.args[0]); network.set("nick", argv.args[0]);
} }
@ -305,6 +306,7 @@ function handleEvent(argv) {
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");
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
@ -331,6 +333,7 @@ function handleEvent(argv) {
case "rpl_namreply": case "rpl_namreply":
var names = argv.args[3].split(' '); 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]});
if (typeof channel === "undefined") { if (typeof channel === "undefined") {
channel = channels.add( channel = channels.add(
new models.Channel({ new models.Channel({
@ -355,6 +358,7 @@ function handleEvent(argv) {
case "rpl_endofnames": case "rpl_endofnames":
var channel = network.get("channels").findWhere({name: argv.args[1]}); var channel = network.get("channels").findWhere({name: argv.args[1]});
var users = channel.get("users"); var users = channel.get("users");
users.trigger( users.trigger(
"add", {}, users "add", {}, users
); );
@ -373,6 +377,39 @@ function handleEvent(argv) {
); );
break; break;
case "rpl_whoisuser":
case "rpl_whoischannels":
case "rpl_whoisserver":
case "rpl_endofwhois":
var channel = channels.findWhere({name: argv.args[1]});
var message = argv.args.slice(2).join(" ");
if (typeof channel == "undefined") {
channel = channels.add(
new models.Channel({
name: argv.args[1]
})
);
}
channel.get("messages").add(
new models.Message({
user: argv.args[1],
text: message
})
);
break;
case "ERROR":
var args = argv.args;
channels.first().get("messages").add(
new models.Message({
text: args[args.length - 1],
type: "error"
})
);
break;
} }
// Debug // Debug