Added whois
This commit is contained in:
parent
c3aee3d025
commit
9119555f44
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
node_modules/
|
||||
!node_modules/slate-irc
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "node_modules/slate-irc"]
|
||||
path = node_modules/slate-irc
|
||||
url = http://github.com/erming/slate-irc
|
@ -194,6 +194,9 @@ h2 {
|
||||
line-height: 1.4em;
|
||||
padding: 0 6px;
|
||||
}
|
||||
#chat .message div {
|
||||
display: inline;
|
||||
}
|
||||
#chat .message .time {
|
||||
color: #bbb;
|
||||
}
|
||||
|
@ -109,9 +109,9 @@
|
||||
<script type="text/html" id="message">
|
||||
{{#messages}}
|
||||
<div class="message {{type}}">
|
||||
<span class="time">{{time}}</span>
|
||||
<a href="{{from}}" class="user">{{mode}}{{from}}</a>
|
||||
<span class="text">{{type}} {{message}}</span>
|
||||
<div class="time">{{time}}</div>
|
||||
<div class="user">{{from}}</div>
|
||||
<div class="text">{{type}} {{message}}</div>
|
||||
</div>
|
||||
{{/messages}}
|
||||
</script>
|
||||
|
@ -31,7 +31,7 @@ $(function() {
|
||||
var html = "";
|
||||
var partials = {
|
||||
users: render("#user"),
|
||||
messages: render("#message")
|
||||
messages: render("#message"),
|
||||
};
|
||||
json.forEach(function(network) {
|
||||
html += render("#window", network, partials);
|
||||
|
@ -40,7 +40,7 @@ models.Message = Backbone.Model.extend({
|
||||
defaults: {
|
||||
type: "",
|
||||
time: "",
|
||||
from: "",
|
||||
from: "-!-",
|
||||
message: "",
|
||||
},
|
||||
initialize: function() {
|
||||
|
103
lib/server.js
103
lib/server.js
@ -59,8 +59,8 @@ function connect(host) {
|
||||
client.user("t_user", "temp user");
|
||||
|
||||
events.forEach(function(e) {
|
||||
client.on(e, function(data) {
|
||||
event.apply(network, [e, data]);
|
||||
client.on(e, function() {
|
||||
event.apply(network, [e, arguments]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -127,6 +127,16 @@ function input(json) {
|
||||
}
|
||||
break;
|
||||
|
||||
case "query":
|
||||
case "whois":
|
||||
if (client && args[1]) {
|
||||
client["whois"](args[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
case "kick":
|
||||
break;
|
||||
|
||||
case "quit":
|
||||
case "disconnect":
|
||||
networks.remove(network);
|
||||
@ -142,10 +152,10 @@ function event(event, data) {
|
||||
switch (event) {
|
||||
|
||||
case "join":
|
||||
var chan = channels.findWhere({name: data.channel}) || channels.add({name: data.channel});
|
||||
chan.addUser({name: data.nick});
|
||||
var chan = channels.findWhere({name: data[0].channel}) || channels.add({name: data[0].channel});
|
||||
chan.addUser({name: data[0].nick});
|
||||
chan.addMessage({
|
||||
from: data.nick,
|
||||
from: data[0].nick,
|
||||
type: "join",
|
||||
});
|
||||
break;
|
||||
@ -155,53 +165,65 @@ function event(event, data) {
|
||||
break;
|
||||
|
||||
case "message":
|
||||
var chan = channels.findWhere({name: data.to}) || channels.add({type: "query", name: data.from});
|
||||
var chan = channels.findWhere({name: data[0].to}) || channels.add({type: "query", name: data[0].from});
|
||||
chan.addMessage({
|
||||
from: data.from,
|
||||
message: data.message
|
||||
from: data[0].from,
|
||||
message: data[0].message
|
||||
});
|
||||
break;
|
||||
|
||||
case "names":
|
||||
var chan = channels.findWhere({name: data.channel});
|
||||
chan.get("users").reset(_.map(data.names, function(n) { return {name: n}; }));
|
||||
var chan = channels.findWhere({name: data[0].channel});
|
||||
chan.get("users").reset(
|
||||
_.map(data[0].names, function(n) {
|
||||
return {name: n};
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
||||
case "nick":
|
||||
if (data[0].new == this.get("client").me) {
|
||||
channels.first().addMessage({
|
||||
message: "You're now known as " + data[0]["new"],
|
||||
});
|
||||
}
|
||||
channels.each(function(chan) {
|
||||
var users = chan.get("users");
|
||||
var user = users.findWhere({name: data.nick});
|
||||
var user = users.findWhere({name: data[0].nick});
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.set("name", data["new"]);
|
||||
user.set("name", data[0]["new"]);
|
||||
users.trigger("change", {}, users);
|
||||
|
||||
chan.addMessage({
|
||||
from: data.nick,
|
||||
message: data["new"],
|
||||
from: data[0].nick,
|
||||
message: data[0]["new"],
|
||||
type: "nick",
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
case "notice":
|
||||
channels.first().addMessage(data);
|
||||
if (data[0].to = "*") {
|
||||
data[0].from = "-!-";
|
||||
}
|
||||
channels.first().addMessage(data[0]);
|
||||
break;
|
||||
|
||||
case "part":
|
||||
var i = data.channels.length;
|
||||
var i = data[0].channels.length;
|
||||
while (i--) {
|
||||
var chan = channels.findWhere({name: data.channels[i]});
|
||||
if (data.nick == this.get("client").me) {
|
||||
var chan = channels.findWhere({name: data[0].channels[i]});
|
||||
if (data[0].nick == this.get("client").me) {
|
||||
channels.remove(chan);
|
||||
return;
|
||||
}
|
||||
var users = chan.get("users");
|
||||
users.remove(users.findWhere({name: data.nick}));
|
||||
users.remove(users.findWhere({name: data[0].nick}));
|
||||
chan.addMessage({
|
||||
from: data.nick,
|
||||
from: data[0].nick,
|
||||
type: "part",
|
||||
});
|
||||
}
|
||||
@ -210,11 +232,11 @@ function event(event, data) {
|
||||
case "quit":
|
||||
channels.each(function(chan) {
|
||||
var users = chan.get("users");
|
||||
var user = users.findWhere({name: data.nick});
|
||||
var user = users.findWhere({name: data[0].nick});
|
||||
if (user) {
|
||||
users.remove(user);
|
||||
chan.addMessage({
|
||||
from: data.nick,
|
||||
from: data[0].nick,
|
||||
type: "quit",
|
||||
});
|
||||
}
|
||||
@ -222,29 +244,50 @@ function event(event, data) {
|
||||
break;
|
||||
|
||||
case "topic":
|
||||
var chan = channels.findWhere({name: data.channel});
|
||||
var from = data.nick;
|
||||
var chan = channels.findWhere({name: data[0].channel});
|
||||
var from = data[0].nick;
|
||||
if (from == this.get("client").me) {
|
||||
from = data.channel;
|
||||
from = data[0].channel;
|
||||
}
|
||||
chan.addMessage({
|
||||
from: from,
|
||||
message: data.topic,
|
||||
message: data[0].topic,
|
||||
type: "topic",
|
||||
});
|
||||
break;
|
||||
|
||||
case "welcome":
|
||||
channels.first().addMessage({message: "Connected."});
|
||||
channels.first().addMessage([
|
||||
{message: "You're now connected to " + this.get("host")},
|
||||
{message: "You're now known as " + data[0]}
|
||||
]);
|
||||
break;
|
||||
|
||||
case "whois":
|
||||
// ..
|
||||
// If this value is null, an error has occured.
|
||||
if (data[1] == null) {
|
||||
channels.first().addMessage({
|
||||
type: "error",
|
||||
message: data[0]
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
var name = data[1].nickname;
|
||||
var chan = channels.findWhere({name: name}) || channels.add({type: "query", name: name});
|
||||
|
||||
var i = 0;
|
||||
for (var k in data[1]) {
|
||||
if (i++ == 5) break;
|
||||
chan.addMessage({
|
||||
message: k + ": " + data[1][k]
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Debug
|
||||
console.log(event + ":");
|
||||
console.log(event);
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
|
1
node_modules/slate-irc
generated
vendored
Submodule
1
node_modules/slate-irc
generated
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6f23d25c4e8163fff06c6d0751219b5d96a3916c
|
Loading…
Reference in New Issue
Block a user