Added input plugins

This commit is contained in:
Mattias Erming 2014-07-03 00:00:11 +02:00
parent f3f3858663
commit 9e41d4d746
19 changed files with 129 additions and 30 deletions

View file

@ -216,6 +216,7 @@ button {
}
#messages .from {
background: #f9f9f9;
border-right: 1px solid #f4f4f4;
color: #ddd;
padding-right: 10px;
text-align: right;

View file

@ -120,17 +120,6 @@ $(function() {
}
});
networks.on("click", ".chan", function() {
var id = $(this).data("id");
var chan = find(id);
if (typeof chan !== "undefined") {
activeChannel = chan;
chat.html(
render("chat", chan)
);
}
});
var input = $("#input").tab(complete, {
hint: false
});
@ -140,10 +129,23 @@ $(function() {
var value = input.val();
input.val("");
socket.emit("input", {
// ..
target: chat.data("target"),
text: value
});
});
networks.on("click", ".chan", function() {
var id = $(this).data("id");
var chan = find(id);
chat.data("target", id);
if (typeof chan !== "undefined") {
activeChannel = chan;
chat.html(
render("chat", chan)
);
}
});
function isActive(chan) {
return activeChannel !== null && chan == activeChannel;
}

View file

@ -20,3 +20,22 @@ Client.prototype.emit = function(event, data) {
this.sockets.in(this.id).emit(event, data);
}
};
Client.prototype.find = function(id) {
var network = null;
var chan = null;
this.networks.forEach(function(n) {
chan = _.find(n.channels, {id: id});
if (chan) {
network = n;
}
});
if (network && chan) {
return {
network: network,
chan: chan
};
} else {
return false;
}
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("action");
};

View file

@ -0,0 +1,3 @@
module.exports = function(network, chan, cmd, args) {
console.log("connect");
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("invite");
};

View file

@ -1,2 +1,9 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
if (cmd != "join") {
return
}
if (args.length != 0) {
var irc = network.irc;
irc.join(args);
}
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("kick");
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("mode");
};

View file

@ -1,2 +1,38 @@
module.exports = function() {
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(network, chan, cmd, args) {
if (cmd != "say" && cmd != "msg") {
return
}
var client = this;
var irc = network.irc;
if (args.length === 0) {
return;
}
var target = args[0].charAt(0) == "#" ? args[0] : "#" + chan.name;
if (target !== chan.name) {
targetChan = _.findWhere(network.channels, {
name: target
});
}
var text = args.join(" ");
irc.send(target, text);
if (typeof chan !== "undefined") {
var msg = new Msg({
type: Msg.Type.MESSAGE,
from: irc.me,
text: text
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
}
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("nick");
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("notice");
};

View file

@ -1,2 +1,10 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
if (cmd != "part") {
return;
}
var irc = network.irc;
if (args.length === 0) {
args.push("#" + chan.name);
}
irc.part(args);
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("quit");
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("raw");
};

View file

@ -1,2 +0,0 @@
module.exports = function() {
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("topic");
};

View file

@ -1,2 +1,3 @@
module.exports = function() {
module.exports = function(network, chan, cmd, args) {
console.log("whois");
};

View file

@ -13,6 +13,7 @@ var clients = [];
var inputs = [
"action",
"connect",
"invite",
"join",
"kick",
@ -23,7 +24,6 @@ var inputs = [
"part",
"quit",
"raw",
"server",
"topic",
"whois"
];
@ -75,7 +75,7 @@ function auth(data) {
// Temporary:
var client = clients[0];
if (clients.length === 0) {
var client = new Client({sockets: sockets});
client = new Client({sockets: sockets});
clients.push(client);
connect(client, {
host: "irc.freenode.org"
@ -126,5 +126,20 @@ function connect(client, args) {
}
function input(client, data) {
console.log(data);
var target = client.find(data.target);
if (!target) {
return;
}
var text = data.text;
if (text.charAt(0) !== "/") {
text = "/say " + text;
}
var args = text.split(" ");
var cmd = args.shift().replace("/", "").toLowerCase();
inputs.forEach(function(plugin) {
require("./plugins/inputs/" + plugin).apply(client, [target.network, target.chan, cmd, args]);
});
}