Sending queries and messages to channels now works
This commit is contained in:
parent
a4a3499a54
commit
57bd684c74
|
@ -11,7 +11,7 @@ var id = 1;
|
|||
models.User = Backbone.Model.extend({
|
||||
defaults: {
|
||||
mode: "",
|
||||
name: ""
|
||||
name: "user"
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -20,10 +20,7 @@ Server.prototype.listen = function(port) {
|
|||
this.networks.on(
|
||||
"all",
|
||||
function(type, data) {
|
||||
if ([
|
||||
"users",
|
||||
"messages"
|
||||
].indexOf(type) != -1) {
|
||||
if (type == "users" || type == "messages") {
|
||||
self.sockets.emit(type, data);
|
||||
} else {
|
||||
self.sockets.emit("networks", self.networks);
|
||||
|
@ -31,11 +28,8 @@ Server.prototype.listen = function(port) {
|
|||
}
|
||||
);
|
||||
|
||||
var options = {
|
||||
log: false
|
||||
};
|
||||
this.sockets = io
|
||||
.listen(http, options)
|
||||
.listen(http, {log: false})
|
||||
.sockets;
|
||||
this.sockets.on("connection", function(socket) {
|
||||
socket.emit(
|
||||
|
@ -65,11 +59,32 @@ function handleInput(input) {
|
|||
|
||||
switch (cmd) {
|
||||
case "":
|
||||
var irc = target.network.irc;
|
||||
if (typeof irc !== "undefined") {
|
||||
irc.say(target.channel.get("name"), input.text);
|
||||
}
|
||||
target.channel.get("messages").add(
|
||||
new models.Message({user: "user", text: input.text})
|
||||
new models.Message({
|
||||
user: target.network.get("nick"),
|
||||
text: input.text
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
||||
case "QUERY":
|
||||
var irc = target.network.irc;
|
||||
if (argv[1] && typeof irc !== "undefined") {
|
||||
var channels = target.network.get("channels");
|
||||
if (argv[1].charAt(0) != "#" && !channels.findWhere({name: argv[1]})) {
|
||||
channels.add(
|
||||
new models.Channel({
|
||||
name: argv[1]
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "JOIN":
|
||||
var irc = target.network.irc;
|
||||
if (argv[1] && typeof irc !== "undefined") {
|
||||
|
@ -79,15 +94,15 @@ function handleInput(input) {
|
|||
|
||||
case "PART":
|
||||
var irc = target.network.irc;
|
||||
if (argv[1] && typeof irc !== "undefined") {
|
||||
irc.part(argv[1]);
|
||||
if (typeof irc !== "undefined") {
|
||||
irc.part(argv[1] ? argv[1] : target.channel.get("name"));
|
||||
}
|
||||
break;
|
||||
|
||||
case "NAMES":
|
||||
var irc = target.network.irc;
|
||||
if (argv[1] && typeof irc !== "undefined") {
|
||||
irc.send("NAMES", argv[1]);
|
||||
if (typeof irc !== "undefined") {
|
||||
irc.send("NAMES", argv[1] ? argv[1] : target.channel.get("name"));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -97,6 +112,9 @@ function handleInput(input) {
|
|||
var network = this.networks.add(
|
||||
new models.Network({host: argv[1]})
|
||||
);
|
||||
network.irc.addListener(
|
||||
"error", function() { /* .. */ }
|
||||
);
|
||||
network.irc.addListener(
|
||||
"raw",
|
||||
function() {
|
||||
|
@ -135,6 +153,31 @@ function handleEvent(argv) {
|
|||
var event = argv.command;
|
||||
switch (event) {
|
||||
|
||||
case "PRIVMSG":
|
||||
var target = argv.args[0];
|
||||
if (target.charAt(0) != "#") {
|
||||
target = argv.nick;
|
||||
}
|
||||
|
||||
var channel = channels.findWhere({name: target});
|
||||
var message = argv.args[1];
|
||||
|
||||
if (typeof channel == "undefined") {
|
||||
channel = channels.add(
|
||||
new models.Channel({
|
||||
name: target
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
channel.get("messages").add(
|
||||
new models.Message({
|
||||
user: argv.nick,
|
||||
text: message
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
||||
case "JOIN":
|
||||
if (argv.nick == network.get("nick")) {
|
||||
channels.add(
|
||||
|
@ -205,6 +248,17 @@ function handleEvent(argv) {
|
|||
"add", {}, users
|
||||
);
|
||||
break;
|
||||
|
||||
case "err_cannotsendtochan":
|
||||
case "err_nosuchnick":
|
||||
var channel = network.get("channels").findWhere({name: argv.args[1]});
|
||||
var messages = channel.get("messages");
|
||||
messages.add(
|
||||
new models.Message({
|
||||
text: argv.args[2]
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
// Debug
|
||||
|
|
Loading…
Reference in New Issue