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) {
var libs = "client/js/libs/**/*.js";
grunt.initConfig({
watch: {
files: libs,
tasks: ["uglify"]
},
uglify: {
options: {
compress: false
},
js: {
files: {
"client/js/libs.min.js": libs
}
}
}
});
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.registerTask(
"default",
["uglify"]
);
};
module.exports = function(grunt) {
var libs = "client/js/libs/**/*.js";
grunt.initConfig({
watch: {
files: libs,
tasks: ["uglify"]
},
uglify: {
options: {
compress: false
},
js: {
files: {
"client/js/libs.min.js": libs
}
}
}
});
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.registerTask(
"default",
["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"?>
<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">
<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" />
</g>
</svg>
<?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">
<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="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>
</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: *
Disallow: /
User-agent: *
Disallow: /

View file

@ -1,225 +1,225 @@
var _ = require("lodash");
var config = require("../config");
var net = require("net");
var Msg = require("./models/msg");
var Network = require("./models/network");
var slate = require("slate-irc");
var tls = require("tls");
module.exports = Client;
var id = 0;
var events = [
"ctcp",
"error",
"image",
"join",
"kick",
"mode",
"motd",
"message",
"names",
"nick",
"notice",
"part",
"quit",
"topic",
"welcome",
"whois"
];
var inputs = [
"action",
"connect",
"invite",
"join",
"kick",
"mode",
"msg",
"nick",
"notice",
"part",
"quit",
"raw",
"topic",
"whois"
];
function Client(sockets, config) {
_.merge(this, {
config: config,
id: id++,
name: "",
networks: [],
sockets: sockets
});
if (config) {
var client = this;
var delay = 0;
(config.networks || []).forEach(function(n) {
setTimeout(function() {
client.connect(n);
}, delay);
delay += 1000;
});
}
}
Client.prototype.emit = function(event, data) {
if (this.sockets !== null) {
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);
}
});
var _ = require("lodash");
var config = require("../config");
var net = require("net");
var Msg = require("./models/msg");
var Network = require("./models/network");
var slate = require("slate-irc");
var tls = require("tls");
module.exports = Client;
var id = 0;
var events = [
"ctcp",
"error",
"image",
"join",
"kick",
"mode",
"motd",
"message",
"names",
"nick",
"notice",
"part",
"quit",
"topic",
"welcome",
"whois"
];
var inputs = [
"action",
"connect",
"invite",
"join",
"kick",
"mode",
"msg",
"nick",
"notice",
"part",
"quit",
"raw",
"topic",
"whois"
];
function Client(sockets, config) {
_.merge(this, {
config: config,
id: id++,
name: "",
networks: [],
sockets: sockets
});
if (config) {
var client = this;
var delay = 0;
(config.networks || []).forEach(function(n) {
setTimeout(function() {
client.connect(n);
}, delay);
delay += 1000;
});
}
}
Client.prototype.emit = function(event, data) {
if (this.sockets !== null) {
this.sockets.in(this.id).emit(event, data);
}
};
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.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) {
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 bcrypt = require("bcrypt");
var fs = require("fs");
var program = require("commander");
var mkdirp = require("mkdirp");
var ClientManager = new require("../clientManager");
var bcrypt = require("bcrypt");
var fs = require("fs");
var program = require("commander");
var mkdirp = require("mkdirp");
const HOME = process.env.HOME + "/.shout";
program
.command("add <name>")
.description("Add a new user")
.action(function(name) {
program
.command("add <name>")
.description("Add a new user")
.action(function(name) {
var path = Helper.resolveHomePath("users");
try {
mkdirp.sync(path);
} catch (e) {
console.log("");
console.log("Could not create " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
try {
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);
} catch (e) {
console.log("");
console.log("You have no permissions to write to " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
var manager = new ClientManager();
var users = manager.getUsers();
if (users.indexOf(name) !== -1) {
console.log("");
console.log("User '" + name + "' already exists.");
console.log("");
return;
}
require("read")({
try {
mkdirp.sync(path);
} catch (e) {
console.log("");
console.log("Could not create " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
try {
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);
} catch (e) {
console.log("");
console.log("You have no permissions to write to " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
var manager = new ClientManager();
var users = manager.getUsers();
if (users.indexOf(name) !== -1) {
console.log("");
console.log("User '" + name + "' already exists.");
console.log("");
return;
}
require("read")({
prompt: "Password: ",
silent: true
}, function(err, password) {
console.log("");
if (err) {
return;
}
var hash = bcrypt.hashSync(password, 8);
manager.addUser(
name,
hash
);
console.log("Added '" + name + "'.");
console.log("");
});
});
}, function(err, password) {
console.log("");
if (err) {
return;
}
var hash = bcrypt.hashSync(password, 8);
manager.addUser(
name,
hash
);
console.log("Added '" + name + "'.");
console.log("");
});
});

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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