Normalize line endings

This commit is contained in:
Mattias Erming 2014-09-13 14:29:45 -07:00
parent 055953fcf2
commit 41027adc69
43 changed files with 19774 additions and 19774 deletions

View file

@ -1,25 +1,25 @@
module.exports = function(grunt) { module.exports = function(grunt) {
var libs = "client/js/libs/**/*.js"; var libs = "client/js/libs/**/*.js";
grunt.initConfig({ grunt.initConfig({
watch: { watch: {
files: libs, files: libs,
tasks: ["uglify"] tasks: ["uglify"]
}, },
uglify: { uglify: {
options: { options: {
compress: false compress: false
}, },
js: { js: {
files: { files: {
"client/js/libs.min.js": libs "client/js/libs.min.js": libs
} }
} }
} }
}); });
grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-watch");
grunt.registerTask( grunt.registerTask(
"default", "default",
["uglify"] ["uglify"]
); );
}; };

2566
client/css/bootstrap.css vendored

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<svg enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <svg enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="chat_x5F_support"> <g id="chat_x5F_support">
<path d="M170.542,357.786c-15.944-2.444-31.341-6.704-46.024-12.779l-5.493-2.272l-44.78,16.973l15.091-33.515 l-8.914-7.281C48.552,292.879,31,258.503,31,222.119C31,145.96,108.141,84,202.96,84c66.491,0,124.284,30.47,152.885,74.937 c6.45,0.715,12.819,1.716,19.08,3.013C346.379,107.298,280.133,69,202.96,69C99.705,69,16,137.554,16,222.119 c0,42.354,20.999,80.691,54.934,108.411l-25.235,56.04l73.085-27.701c18.762,7.762,39.34,13.007,61.07,15.203 C176.34,368.804,173.231,363.368,170.542,357.786z" fill="#818B9E" /> <path d="M170.542,357.786c-15.944-2.444-31.341-6.704-46.024-12.779l-5.493-2.272l-44.78,16.973l15.091-33.515 l-8.914-7.281C48.552,292.879,31,258.503,31,222.119C31,145.96,108.141,84,202.96,84c66.491,0,124.284,30.47,152.885,74.937 c6.45,0.715,12.819,1.716,19.08,3.013C346.379,107.298,280.133,69,202.96,69C99.705,69,16,137.554,16,222.119 c0,42.354,20.999,80.691,54.934,108.411l-25.235,56.04l73.085-27.701c18.762,7.762,39.34,13.007,61.07,15.203 C176.34,368.804,173.231,363.368,170.542,357.786z" fill="#818B9E" />
<path d="M492,303.273c0-72.144-71.411-130.629-159.5-130.629S173,231.128,173,303.273s71.411,130.629,159.5,130.629 c25.834,0,50.229-5.036,71.813-13.965l62.35,23.633l-21.528-47.809C474.085,372.112,492,339.406,492,303.273z M253.5,334.606 c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5c14.636,0,26.5,11.864,26.5,26.5S268.136,334.606,253.5,334.606z M332.5,334.606c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5s26.5,11.864,26.5,26.5S347.136,334.606,332.5,334.606z M411.5,334.606c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5s26.5,11.864,26.5,26.5S426.136,334.606,411.5,334.606z" fill="#f2f3f5" /> <path d="M492,303.273c0-72.144-71.411-130.629-159.5-130.629S173,231.128,173,303.273s71.411,130.629,159.5,130.629 c25.834,0,50.229-5.036,71.813-13.965l62.35,23.633l-21.528-47.809C474.085,372.112,492,339.406,492,303.273z M253.5,334.606 c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5c14.636,0,26.5,11.864,26.5,26.5S268.136,334.606,253.5,334.606z M332.5,334.606c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5s26.5,11.864,26.5,26.5S347.136,334.606,332.5,334.606z M411.5,334.606c-14.636,0-26.5-11.864-26.5-26.5s11.864-26.5,26.5-26.5s26.5,11.864,26.5,26.5S426.136,334.606,411.5,334.606z" fill="#f2f3f5" />
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

18380
client/js/libs/jquery.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,2 @@
User-agent: * User-agent: *
Disallow: / Disallow: /

View file

@ -1,225 +1,225 @@
var _ = require("lodash"); var _ = require("lodash");
var config = require("../config"); var config = require("../config");
var net = require("net"); var net = require("net");
var Msg = require("./models/msg"); var Msg = require("./models/msg");
var Network = require("./models/network"); var Network = require("./models/network");
var slate = require("slate-irc"); var slate = require("slate-irc");
var tls = require("tls"); var tls = require("tls");
module.exports = Client; module.exports = Client;
var id = 0; var id = 0;
var events = [ var events = [
"ctcp", "ctcp",
"error", "error",
"image", "image",
"join", "join",
"kick", "kick",
"mode", "mode",
"motd", "motd",
"message", "message",
"names", "names",
"nick", "nick",
"notice", "notice",
"part", "part",
"quit", "quit",
"topic", "topic",
"welcome", "welcome",
"whois" "whois"
]; ];
var inputs = [ var inputs = [
"action", "action",
"connect", "connect",
"invite", "invite",
"join", "join",
"kick", "kick",
"mode", "mode",
"msg", "msg",
"nick", "nick",
"notice", "notice",
"part", "part",
"quit", "quit",
"raw", "raw",
"topic", "topic",
"whois" "whois"
]; ];
function Client(sockets, config) { function Client(sockets, config) {
_.merge(this, { _.merge(this, {
config: config, config: config,
id: id++, id: id++,
name: "", name: "",
networks: [], networks: [],
sockets: sockets sockets: sockets
}); });
if (config) { if (config) {
var client = this; var client = this;
var delay = 0; var delay = 0;
(config.networks || []).forEach(function(n) { (config.networks || []).forEach(function(n) {
setTimeout(function() { setTimeout(function() {
client.connect(n); client.connect(n);
}, delay); }, delay);
delay += 1000; delay += 1000;
}); });
} }
} }
Client.prototype.emit = function(event, data) { Client.prototype.emit = function(event, data) {
if (this.sockets !== null) { if (this.sockets !== null) {
this.sockets.in(this.id).emit(event, data); this.sockets.in(this.id).emit(event, data);
} }
};
Client.prototype.find = function(id) {
var network = null;
var chan = null;
for (var i in this.networks) {
var n = this.networks[i];
chan = _.find(n.channels, {id: id});
if (chan) {
network = n;
break;
}
}
if (network && chan) {
return {
network: network,
chan: chan
};
} else {
return false;
}
};
Client.prototype.connect = function(args) {
var client = this;
var server = {
host: args.host || "irc.freenode.org",
port: args.port || (args.tls ? 6697 : 6667),
name: args.name || "",
rejectUnauthorized: false
};
var stream = args.tls ? tls.connect(server) : net.connect(server);
stream.on("error", function(e) {
console.log("Client#connect():\n" + e);
stream.end();
var msg = new Msg({
type: Msg.Type.ERROR,
text: "Connection error."
});
client.emit("msg", {
msg: msg
});
});
var nick = args.nick || "shout-user";
var realname = args.realname || "Shout User";
var irc = slate(stream);
if (args.password) {
irc.pass(args.password);
}
irc.me = nick;
irc.nick(nick);
irc.user(nick, realname);
var network = new Network({
host: server.host,
name: server.name,
irc: irc
});
client.networks.push(network);
client.emit("network", {
network: network
});
events.forEach(function(plugin) {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
irc,
network
]);
});
irc.once("welcome", function() {
var delay = 1000;
var commands = args.commands;
if (Array.isArray(commands)) {
commands.forEach(function(cmd) {
setTimeout(function() {
client.input({
target: network.channels[0].id,
text: cmd
});
}, delay);
delay += 1000;
});
}
setTimeout(function() {
irc.write("PING " + network.host);
}, delay);
});
irc.once("pong", function() {
var join = (args.join || "");
if (join) {
join = join.replace(/\,/g, " ").split(/\s+/g);
irc.join(join);
}
});
};
Client.prototype.input = function(data) {
var client = this;
var text = data.text;
var target = client.find(data.target);
if (text.charAt(0) !== "/") {
text = "/say " + text;
}
var args = text.split(" ");
var cmd = args.shift().replace("/", "").toLowerCase();
_.each(inputs, function(plugin) {
try {
var path = "./plugins/inputs/" + plugin;
var fn = require(path);
fn.apply(client, [
target.network,
target.chan,
cmd,
args
]);
} catch (e) {
console.log(path + ": " + e);
}
});
}; };
Client.prototype.more = function(data) { Client.prototype.find = function(id) {
var client = this; var network = null;
var target = client.find(data.target); var chan = null;
if (!target) { for (var i in this.networks) {
return; var n = this.networks[i];
} chan = _.find(n.channels, {id: id});
var chan = target.chan; if (chan) {
var count = chan.messages.length - (data.count || 0); network = n;
var messages = chan.messages.slice(Math.max(0, count - 100), count); break;
client.emit("more", { }
chan: chan.id, }
messages: messages if (network && chan) {
}); return {
network: network,
chan: chan
};
} else {
return false;
}
};
Client.prototype.connect = function(args) {
var client = this;
var server = {
host: args.host || "irc.freenode.org",
port: args.port || (args.tls ? 6697 : 6667),
name: args.name || "",
rejectUnauthorized: false
};
var stream = args.tls ? tls.connect(server) : net.connect(server);
stream.on("error", function(e) {
console.log("Client#connect():\n" + e);
stream.end();
var msg = new Msg({
type: Msg.Type.ERROR,
text: "Connection error."
});
client.emit("msg", {
msg: msg
});
});
var nick = args.nick || "shout-user";
var realname = args.realname || "Shout User";
var irc = slate(stream);
if (args.password) {
irc.pass(args.password);
}
irc.me = nick;
irc.nick(nick);
irc.user(nick, realname);
var network = new Network({
host: server.host,
name: server.name,
irc: irc
});
client.networks.push(network);
client.emit("network", {
network: network
});
events.forEach(function(plugin) {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
irc,
network
]);
});
irc.once("welcome", function() {
var delay = 1000;
var commands = args.commands;
if (Array.isArray(commands)) {
commands.forEach(function(cmd) {
setTimeout(function() {
client.input({
target: network.channels[0].id,
text: cmd
});
}, delay);
delay += 1000;
});
}
setTimeout(function() {
irc.write("PING " + network.host);
}, delay);
});
irc.once("pong", function() {
var join = (args.join || "");
if (join) {
join = join.replace(/\,/g, " ").split(/\s+/g);
irc.join(join);
}
});
};
Client.prototype.input = function(data) {
var client = this;
var text = data.text;
var target = client.find(data.target);
if (text.charAt(0) !== "/") {
text = "/say " + text;
}
var args = text.split(" ");
var cmd = args.shift().replace("/", "").toLowerCase();
_.each(inputs, function(plugin) {
try {
var path = "./plugins/inputs/" + plugin;
var fn = require(path);
fn.apply(client, [
target.network,
target.chan,
cmd,
args
]);
} catch (e) {
console.log(path + ": " + e);
}
});
};
Client.prototype.more = function(data) {
var client = this;
var target = client.find(data.target);
if (!target) {
return;
}
var chan = target.chan;
var count = chan.messages.length - (data.count || 0);
var messages = chan.messages.slice(Math.max(0, count - 100), count);
client.emit("more", {
chan: chan.id,
messages: messages
});
};
Client.prototype.quit = function() {
this.networks.forEach(function(network) {
var irc = network.irc;
if (network.connected) {
irc.quit();
} else {
irc.stream.end();
}
});
}; };
Client.prototype.quit = function() {
this.networks.forEach(function(network) {
var irc = network.irc;
if (network.connected) {
irc.quit();
} else {
irc.stream.end();
}
});
};

View file

@ -1,58 +1,58 @@
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var bcrypt = require("bcrypt"); var bcrypt = require("bcrypt");
var fs = require("fs"); var fs = require("fs");
var program = require("commander"); var program = require("commander");
var mkdirp = require("mkdirp"); var mkdirp = require("mkdirp");
const HOME = process.env.HOME + "/.shout"; const HOME = process.env.HOME + "/.shout";
program program
.command("add <name>") .command("add <name>")
.description("Add a new user") .description("Add a new user")
.action(function(name) { .action(function(name) {
var path = Helper.resolveHomePath("users"); var path = Helper.resolveHomePath("users");
try { try {
mkdirp.sync(path); mkdirp.sync(path);
} catch (e) { } catch (e) {
console.log(""); console.log("");
console.log("Could not create " + path); console.log("Could not create " + path);
console.log("Try running the command as sudo."); console.log("Try running the command as sudo.");
console.log(""); console.log("");
return; return;
} }
try { try {
var test = path + "/.test"; var test = path + "/.test";
fs.mkdirSync(test); fs.mkdirSync(test);
fs.rmdirSync(test); fs.rmdirSync(test);
} catch (e) { } catch (e) {
console.log(""); console.log("");
console.log("You have no permissions to write to " + path); console.log("You have no permissions to write to " + path);
console.log("Try running the command as sudo."); console.log("Try running the command as sudo.");
console.log(""); console.log("");
return; return;
} }
var manager = new ClientManager(); var manager = new ClientManager();
var users = manager.getUsers(); var users = manager.getUsers();
if (users.indexOf(name) !== -1) { if (users.indexOf(name) !== -1) {
console.log(""); console.log("");
console.log("User '" + name + "' already exists."); console.log("User '" + name + "' already exists.");
console.log(""); console.log("");
return; return;
} }
require("read")({ require("read")({
prompt: "Password: ", prompt: "Password: ",
silent: true silent: true
}, function(err, password) { }, function(err, password) {
console.log(""); console.log("");
if (err) { if (err) {
return; return;
} }
var hash = bcrypt.hashSync(password, 8); var hash = bcrypt.hashSync(password, 8);
manager.addUser( manager.addUser(
name, name,
hash hash
); );
console.log("Added '" + name + "'."); console.log("Added '" + name + "'.");
console.log(""); console.log("");
}); });
}); });

View file

@ -1,21 +1,21 @@
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var program = require("commander"); var program = require("commander");
program program
.command("list") .command("list")
.description("List all existing users") .description("List all existing users")
.action(function() { .action(function() {
var users = new ClientManager().getUsers(); var users = new ClientManager().getUsers();
if (!users.length) { if (!users.length) {
console.log(""); console.log("");
console.log("No users found!"); console.log("No users found!");
console.log(""); console.log("");
} else { } else {
console.log(""); console.log("");
console.log("Users:"); console.log("Users:");
for (var i = 0; i < users.length; i++) { for (var i = 0; i < users.length; i++) {
console.log(" " + (i + 1) + ". " + users[i]); console.log(" " + (i + 1) + ". " + users[i]);
} }
console.log(""); console.log("");
} }
}); });

View file

@ -1,32 +1,32 @@
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var fs = require("fs"); var fs = require("fs");
var program = require("commander"); var program = require("commander");
var Helper = require("../helper"); var Helper = require("../helper");
program program
.command("remove <name>") .command("remove <name>")
.description("Remove an existing user") .description("Remove an existing user")
.action(function(name) { .action(function(name) {
try { try {
var path = Helper.resolveHomePath("users"); var path = Helper.resolveHomePath("users");
var test = path + "/.test"; var test = path + "/.test";
fs.mkdirSync(test); fs.mkdirSync(test);
fs.rmdirSync(test); fs.rmdirSync(test);
} catch (e) { } catch (e) {
console.log(""); console.log("");
console.log("You have no permissions to delete from " + path); console.log("You have no permissions to delete from " + path);
console.log("Try running the command as sudo."); console.log("Try running the command as sudo.");
console.log(""); console.log("");
return; return;
} }
var manager = new ClientManager(); var manager = new ClientManager();
if (manager.removeUser(name)) { if (manager.removeUser(name)) {
console.log(""); console.log("");
console.log("Removed '" + name + "'."); console.log("Removed '" + name + "'.");
console.log(""); console.log("");
} else { } else {
console.log(""); console.log("");
console.log("User '" + name + "' doesn't exist."); console.log("User '" + name + "' doesn't exist.");
console.log(""); console.log("");
} }
}); });

View file

@ -1,46 +1,46 @@
var _ = require("lodash"); var _ = require("lodash");
module.exports = Chan; module.exports = Chan;
Chan.Type = { Chan.Type = {
CHANNEL: "channel", CHANNEL: "channel",
LOBBY: "lobby", LOBBY: "lobby",
QUERY: "query" QUERY: "query"
}; };
var id = 0; var id = 0;
function Chan(attr) { function Chan(attr) {
_.merge(this, _.extend({ _.merge(this, _.extend({
id: id++, id: id++,
messages: [], messages: [],
name: "", name: "",
type: Chan.Type.CHANNEL, type: Chan.Type.CHANNEL,
users: [] users: []
}, attr)); }, attr));
} }
Chan.prototype.sortUsers = function() { Chan.prototype.sortUsers = function() {
this.users = _.sortBy( this.users = _.sortBy(
this.users, this.users,
function(u) { return u.name.toLowerCase(); } function(u) { return u.name.toLowerCase(); }
); );
var modes = [ var modes = [
"~", "~",
"%", "%",
"@", "@",
"+", "+",
].reverse(); ].reverse();
modes.forEach(function(mode) { modes.forEach(function(mode) {
this.users = _.remove( this.users = _.remove(
this.users, this.users,
function(u) { return u.mode == mode; } function(u) { return u.mode == mode; }
).concat(this.users); ).concat(this.users);
}, this); }, this);
}; };
Chan.prototype.toJSON = function() { Chan.prototype.toJSON = function() {
var clone = _.clone(this); var clone = _.clone(this);
clone.messages = clone.messages.slice(-100); clone.messages = clone.messages.slice(-100);
return clone; return clone;
}; };

View file

@ -1,30 +1,30 @@
var _ = require("lodash"); var _ = require("lodash");
var moment = require("moment"); var moment = require("moment");
Msg.Type = { Msg.Type = {
ACTION: "action", ACTION: "action",
ERROR: "error", ERROR: "error",
IMAGE: "image", IMAGE: "image",
JOIN: "join", JOIN: "join",
KICK: "kick", KICK: "kick",
MESSAGE: "message", MESSAGE: "message",
MODE: "mode", MODE: "mode",
MOTD: "motd", MOTD: "motd",
NICK: "nick", NICK: "nick",
NOTICE: "notice", NOTICE: "notice",
PART: "part", PART: "part",
QUIT: "quit", QUIT: "quit",
TOPIC: "topic", TOPIC: "topic",
WHOIS: "whois" WHOIS: "whois"
}; };
module.exports = Msg; module.exports = Msg;
function Msg(attr) { function Msg(attr) {
_.merge(this, _.extend({ _.merge(this, _.extend({
from: "", from: "",
text: "", text: "",
time: moment().utc().format("HH:mm:ss"), time: moment().utc().format("HH:mm:ss"),
type: Msg.Type.MESSAGE type: Msg.Type.MESSAGE
}, attr)); }, attr));
} }

View file

@ -1,38 +1,38 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("./chan"); var Chan = require("./chan");
module.exports = Network; module.exports = Network;
var id = 0; var id = 0;
function Network(attr) { function Network(attr) {
_.merge(this, _.extend({ _.merge(this, _.extend({
channels: [], channels: [],
connected: false, connected: false,
host: "", host: "",
id: id++, id: id++,
irc: null, irc: null,
}, attr)); }, attr));
this.name = attr.name || prettify(attr.host); this.name = attr.name || prettify(attr.host);
this.channels.unshift( this.channels.unshift(
new Chan({name: this.name, type: Chan.Type.LOBBY}) new Chan({name: this.name, type: Chan.Type.LOBBY})
); );
} }
Network.prototype.toJSON = function() { Network.prototype.toJSON = function() {
return _.omit(this, "irc"); return _.omit(this, "irc");
}; };
function prettify(host) { function prettify(host) {
var name = capitalize(host.split(".")[1]); var name = capitalize(host.split(".")[1]);
if (!name) { if (!name) {
name = host; name = host;
} }
return name; return name;
} }
function capitalize(str) { function capitalize(str) {
if (typeof str === "string") { if (typeof str === "string") {
return str.charAt(0).toUpperCase() + str.slice(1); return str.charAt(0).toUpperCase() + str.slice(1);
} }
} }

View file

@ -1,10 +1,10 @@
var _ = require("lodash"); var _ = require("lodash");
module.exports = User; module.exports = User;
function User(attr) { function User(attr) {
_.merge(this, _.extend({ _.merge(this, _.extend({
mode: "", mode: "",
name: "" name: ""
}, attr)); }, attr));
} }

View file

@ -1,38 +1,38 @@
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "slap" && cmd != "me") { if (cmd != "slap" && cmd != "me") {
return; return;
} }
var client = this; var client = this;
var irc = network.irc; var irc = network.irc;
switch (cmd) { switch (cmd) {
case "slap": case "slap":
var slap = "slaps " + args[0] + " around a bit with a large trout"; var slap = "slaps " + args[0] + " around a bit with a large trout";
/* fall through */ /* fall through */
case "me": case "me":
if (args.length === 0) { if (args.length === 0) {
break; break;
} }
var text = slap || args.join(" "); var text = slap || args.join(" ");
irc.action( irc.action(
chan.name, chan.name,
text text
); );
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.ACTION, type: Msg.Type.ACTION,
from: irc.me, from: irc.me,
text: text text: text
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
break; break;
} }
}; };

View file

@ -1,11 +1,11 @@
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "connect" && cmd != "server") { if (cmd != "connect" && cmd != "server") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var client = this; var client = this;
client.connect({ client.connect({
host: args[0] host: args[0]
}); });
} }
}; };

View file

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

View file

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

View file

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

View file

@ -1,30 +1,30 @@
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "mode" && cmd != "op" && cmd != "voice" && cmd != "deop" && cmd != "devoice") { if (cmd != "mode" && cmd != "op" && cmd != "voice" && cmd != "deop" && cmd != "devoice") {
return; return;
} else if (args.length === 0) { } else if (args.length === 0) {
return; return;
} }
var mode; var mode;
var user; var user;
if (cmd != "mode") { if (cmd != "mode") {
user = args[0]; user = args[0];
mode = { mode = {
"op": "+o", "op": "+o",
"voice": "+v", "voice": "+v",
"deop": "-o", "deop": "-o",
"devoice": "-v" "devoice": "-v"
}[cmd]; }[cmd];
} else if (args.length === 1) { } else if (args.length === 1) {
return; return;
} else { } else {
mode = args[0]; mode = args[0];
user = args[1]; user = args[1];
} }
var irc = network.irc; var irc = network.irc;
irc.mode( irc.mode(
chan.name, chan.name,
mode, mode,
user user
); );
}; };

View file

@ -1,32 +1,32 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "say" && cmd != "msg") { if (cmd != "say" && cmd != "msg") {
return; return;
} }
if (args.length === 0 || args[0] === "") { if (args.length === 0 || args[0] === "") {
return; return;
} }
var client = this; var client = this;
var irc = network.irc; var irc = network.irc;
var target = ""; var target = "";
if (cmd == "msg") { if (cmd == "msg") {
target = args.shift(); target = args.shift();
if (args.length === 0) { if (args.length === 0) {
return; return;
} }
} else { } else {
target = chan.name; target = chan.name;
} }
var text = args.join(" "); var text = args.join(" ");
irc.send(target, text); irc.send(target, text);
var channel = _.find(network.channels, {name: target}); var channel = _.find(network.channels, {name: target});
if (typeof channel !== "undefined") { if (typeof channel !== "undefined") {
irc.emit("message", { irc.emit("message", {
from: irc.me, from: irc.me,
to: channel.name, to: channel.name,
message: text message: text
}); });
} }
}; };

View file

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

View file

@ -1,7 +1,7 @@
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "notice" || !args[1]) { if (cmd != "notice" || !args[1]) {
return; return;
} }
var irc = network.irc; var irc = network.irc;
irc.notice(args[0], args.slice(1).join(" ")); irc.notice(args[0], args.slice(1).join(" "));
}; };

View file

@ -1,20 +1,20 @@
var _ = require("lodash"); var _ = require("lodash");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "part" && cmd != "leave" && cmd != "close") { if (cmd != "part" && cmd != "leave" && cmd != "close") {
return; return;
} }
var client = this; var client = this;
if (chan.type == "query") { if (chan.type == "query") {
network.channels = _.without(network.channels, chan); network.channels = _.without(network.channels, chan);
client.emit("part", { client.emit("part", {
chan: chan.id chan: chan.id
}); });
} else { } else {
var irc = network.irc; var irc = network.irc;
if (args.length === 0) { if (args.length === 0) {
args.push(chan.name); args.push(chan.name);
} }
irc.part(args); irc.part(args);
} }
}; };

View file

@ -1,17 +1,17 @@
var _ = require("lodash"); var _ = require("lodash");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "quit" && cmd != "disconnect") { if (cmd != "quit" && cmd != "disconnect") {
return; return;
} }
var client = this; var client = this;
var irc = network.irc; var irc = network.irc;
client.networks = _.without(client.networks, network); client.networks = _.without(client.networks, network);
client.emit("quit", { client.emit("quit", {
network: network.id network: network.id
}); });
irc.quit(); irc.quit();
}; };

View file

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

View file

@ -1,12 +1,12 @@
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "topic") { if (cmd != "topic") {
return; return;
} }
var msg = "TOPIC"; var msg = "TOPIC";
msg += " " + chan.name; msg += " " + chan.name;
msg += args[0] ? (" :" + args.join(" ")) : ""; msg += args[0] ? (" :" + args.join(" ")) : "";
var irc = network.irc; var irc = network.irc;
irc.write(msg); irc.write(msg);
}; };

View file

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

View file

@ -1,22 +1,22 @@
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("errors", function(data) { irc.on("errors", function(data) {
var lobby = network.channels[0]; var lobby = network.channels[0];
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.message, text: data.message,
}); });
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
if (!network.connected) { if (!network.connected) {
if (data.cmd == "ERR_NICKNAMEINUSE") { if (data.cmd == "ERR_NICKNAMEINUSE") {
var random = irc.me + Math.floor(10 + (Math.random() * 89)); var random = irc.me + Math.floor(10 + (Math.random() * 89));
irc.nick(random); irc.nick(random);
} }
} }
}); });
}; };

View file

@ -1,37 +1,37 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("../../models/chan"); var Chan = require("../../models/chan");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
var User = require("../../models/user"); var User = require("../../models/user");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("join", function(data) { irc.on("join", function(data) {
var chan = _.find(network.channels, {name: data.channel}); var chan = _.find(network.channels, {name: data.channel});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
name: data.channel name: data.channel
}); });
network.channels.push(chan); network.channels.push(chan);
client.emit("join", { client.emit("join", {
network: network.id, network: network.id,
chan: chan chan: chan
}); });
} }
var users = chan.users; var users = chan.users;
users.push(new User({name: data.nick})); users.push(new User({name: data.nick}));
chan.sortUsers(); chan.sortUsers();
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: users users: users
}); });
var msg = new Msg({ var msg = new Msg({
from: data.nick, from: data.nick,
type: Msg.Type.JOIN type: Msg.Type.JOIN
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,31 +1,31 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("kick", function(data) { irc.on("kick", function(data) {
var chan = _.findWhere(network.channels, {name: data.channel}); var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
if (data.client == irc.me) { if (data.client == irc.me) {
chan.users = []; chan.users = [];
} else { } else {
chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.client})); chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.client}));
} }
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: chan.users users: chan.users
}); });
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.KICK, type: Msg.Type.KICK,
from: data.nick, from: data.nick,
text: data.client text: data.client
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,44 +1,44 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("../../models/chan"); var Chan = require("../../models/chan");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("message", function(data) { irc.on("message", function(data) {
var target = data.to; var target = data.to;
if (target.toLowerCase() == irc.me.toLowerCase()) { if (target.toLowerCase() == irc.me.toLowerCase()) {
target = data.from; target = data.from;
} }
var chan = _.findWhere(network.channels, {name: target}); var chan = _.findWhere(network.channels, {name: target});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
type: Chan.Type.QUERY, type: Chan.Type.QUERY,
name: data.from name: data.from
}); });
network.channels.push(chan); network.channels.push(chan);
client.emit("join", { client.emit("join", {
network: network.id, network: network.id,
chan: chan chan: chan
}); });
} }
var type = ""; var type = "";
var text = data.message; var text = data.message;
if (text.split(" ")[0] === "\u0001ACTION") { if (text.split(" ")[0] === "\u0001ACTION") {
type = Msg.Type.ACTION; type = Msg.Type.ACTION;
text = text.replace(/\u0001|ACTION/g, ""); text = text.replace(/\u0001|ACTION/g, "");
} }
text.split(" ").forEach(function(w) { text.split(" ").forEach(function(w) {
if (w.indexOf(irc.me) === 0) type += " highlight"; if (w.indexOf(irc.me) === 0) type += " highlight";
}); });
var msg = new Msg({ var msg = new Msg({
type: type || Msg.Type.MESSAGE, type: type || Msg.Type.MESSAGE,
from: data.from, from: data.from,
text: text text: text
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,28 +1,28 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("mode", function(data) { irc.on("mode", function(data) {
var chan = _.findWhere(network.channels, {name: data.target}); var chan = _.findWhere(network.channels, {name: data.target});
if (typeof chan !== "undefined") { if (typeof chan !== "undefined") {
setTimeout(function() { setTimeout(function() {
irc.write("NAMES " + data.target); irc.write("NAMES " + data.target);
}, 200); }, 200);
var nick = data.nick; var nick = data.nick;
if (nick.indexOf(".") !== -1) { if (nick.indexOf(".") !== -1) {
nick = data.target; nick = data.target;
} }
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.MODE, type: Msg.Type.MODE,
from: nick, from: nick,
text: data.mode + " " + data.client, text: data.mode + " " + data.client,
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg, msg: msg,
}); });
} }
}); });
}; };

View file

@ -1,19 +1,19 @@
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("motd", function(data) { irc.on("motd", function(data) {
var lobby = network.channels[0]; var lobby = network.channels[0];
data.motd.forEach(function(text) { data.motd.forEach(function(text) {
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.MOTD, type: Msg.Type.MOTD,
text: text text: text
}); });
lobby.messages.push(msg); lobby.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
}); });
}); });
}; };

View file

@ -1,21 +1,21 @@
var _ = require("lodash"); var _ = require("lodash");
var User = require("../../models/user"); var User = require("../../models/user");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("names", function(data) { irc.on("names", function(data) {
var chan = _.findWhere(network.channels, {name: data.channel}); var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
chan.users = []; chan.users = [];
_.each(data.names, function(u) { _.each(data.names, function(u) {
chan.users.push(new User(u)); chan.users.push(new User(u));
}); });
chan.sortUsers(); chan.sortUsers();
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: chan.users users: chan.users
}); });
}); });
}; };

View file

@ -1,41 +1,41 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("nick", function(data) { irc.on("nick", function(data) {
if (data["new"] == irc.me) { if (data["new"] == irc.me) {
var lobby = network.channels[0]; var lobby = network.channels[0];
var msg = new Msg({ var msg = new Msg({
text: "You're now known as " + data["new"], text: "You're now known as " + data["new"],
}); });
lobby.messages.push(msg); lobby.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
} }
network.channels.forEach(function(chan) { network.channels.forEach(function(chan) {
var user = _.findWhere(chan.users, {name: data.nick}); var user = _.findWhere(chan.users, {name: data.nick});
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }
user.name = data["new"]; user.name = data["new"];
chan.sortUsers(); chan.sortUsers();
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: chan.users users: chan.users
}); });
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.NICK, type: Msg.Type.NICK,
from: data.nick, from: data.nick,
text: data["new"] text: data["new"]
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}); });
}; };

View file

@ -1,22 +1,22 @@
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("notice", function(data) { irc.on("notice", function(data) {
var lobby = network.channels[0]; var lobby = network.channels[0];
var from = data.from || ""; var from = data.from || "";
if (data.to == "*" || data.from.indexOf(".") !== -1) { if (data.to == "*" || data.from.indexOf(".") !== -1) {
from = ""; from = "";
} }
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.NOTICE, type: Msg.Type.NOTICE,
from: from, from: from,
text: data.message text: data.message
}); });
lobby.messages.push(msg); lobby.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,34 +1,34 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("part", function(data) { irc.on("part", function(data) {
var chan = _.findWhere(network.channels, {name: data.channels[0]}); var chan = _.findWhere(network.channels, {name: data.channels[0]});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
if (data.nick == irc.me) { if (data.nick == irc.me) {
network.channels = _.without(network.channels, chan); network.channels = _.without(network.channels, chan);
client.emit("part", { client.emit("part", {
chan: chan.id chan: chan.id
}); });
} else { } else {
var user = _.findWhere(chan.users, {name: data.nick}); var user = _.findWhere(chan.users, {name: data.nick});
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: chan.users users: chan.users
}); });
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.PART, type: Msg.Type.PART,
from: data.nick from: data.nick
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
} }
}); });
}; };

View file

@ -1,28 +1,28 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("quit", function(data) { irc.on("quit", function(data) {
network.channels.forEach(function(chan) { network.channels.forEach(function(chan) {
var user = _.findWhere(chan.users, {name: data.nick}); var user = _.findWhere(chan.users, {name: data.nick});
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
users: chan.users users: chan.users
}); });
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.QUIT, type: Msg.Type.QUIT,
from: data.nick from: data.nick
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}); });
}; };

View file

@ -1,23 +1,23 @@
var _ = require("lodash"); var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("topic", function(data) { irc.on("topic", function(data) {
var chan = _.findWhere(network.channels, {name: data.channel}); var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
var from = data.nick || chan.name; var from = data.nick || chan.name;
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.TOPIC, type: Msg.Type.TOPIC,
from: from, from: from,
text: data.topic, text: data.topic,
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,18 +1,18 @@
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("welcome", function(data) { irc.on("welcome", function(data) {
network.connected = true; network.connected = true;
irc.write("PING " + network.host); irc.write("PING " + network.host);
var lobby = network.channels[0]; var lobby = network.channels[0];
var msg = new Msg({ var msg = new Msg({
text: "You're now known as " + data text: "You're now known as " + data
}); });
lobby.messages.push(msg); lobby.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
}); });
}; };

View file

@ -1,47 +1,47 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("../../models/chan"); var Chan = require("../../models/chan");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("whois", function(err, data) { irc.on("whois", function(err, data) {
if (data === null) { if (data === null) {
return; return;
} }
var chan = _.findWhere(network.channels, {name: data.nickname}); var chan = _.findWhere(network.channels, {name: data.nickname});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
type: Chan.Type.QUERY, type: Chan.Type.QUERY,
name: data.nickname name: data.nickname
}); });
network.channels.push(chan); network.channels.push(chan);
client.emit("join", { client.emit("join", {
network: network.id, network: network.id,
chan: chan chan: chan
}); });
} }
var prefix = { var prefix = {
hostname: "from", hostname: "from",
realname: "is", realname: "is",
channels: "on", channels: "on",
server: "using" server: "using"
}; };
var i = 0; var i = 0;
for (var k in data) { for (var k in data) {
var key = prefix[k]; var key = prefix[k];
if (!key || data[k].toString() === "") { if (!key || data[k].toString() === "") {
continue; continue;
} }
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.WHOIS, type: Msg.Type.WHOIS,
from: data.nickname, from: data.nickname,
text: key + " " + data[k] text: key + " " + data[k]
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
} }
}); });
}; };