Comply with ESLint

This commit is contained in:
William Boman 2015-10-01 00:39:57 +02:00
parent a69992f6b2
commit 8fdfd70c7e
40 changed files with 164 additions and 175 deletions

View File

@ -35,11 +35,12 @@ $(function() {
$("html").addClass("web-app-mode"); $("html").addClass("web-app-mode");
} }
var pop;
try { try {
var pop = new Audio(); pop = new Audio();
pop.src = "/audio/pop.ogg"; pop.src = "/audio/pop.ogg";
} catch(e) { } catch (e) {
var pop = { pop = {
play: $.noop play: $.noop
}; };
} }
@ -73,7 +74,7 @@ $(function() {
}); });
}); });
socket.on("auth", function(data) { socket.on("auth", function(/* data */) {
var body = $("body"); var body = $("body");
var login = $("#sign-in"); var login = $("#sign-in");
if (!login.length) { if (!login.length) {
@ -183,7 +184,7 @@ $(function() {
socket.on("msg", function(data) { socket.on("msg", function(data) {
var target = "#chan-" + data.chan; var target = "#chan-" + data.chan;
if (data.msg.type == "error") { if (data.msg.type === "error") {
target = "#chan-" + chat.find(".active").data("id"); target = "#chan-" + chat.find(".active").data("id");
} }
@ -202,7 +203,7 @@ $(function() {
} }
var type = data.msg.type; var type = data.msg.type;
if (type == "message" || type == "action") { if (type === "message" || type === "action") {
var nicks = chan.find(".users").data("nicks"); var nicks = chan.find(".users").data("nicks");
if (nicks) { if (nicks) {
var find = nicks.indexOf(from); var find = nicks.indexOf(from);
@ -220,7 +221,7 @@ $(function() {
.find(".messages") .find(".messages")
.prepend(render("msg", {messages: data.messages})) .prepend(render("msg", {messages: data.messages}))
.end(); .end();
if (data.messages.length != 100) { if (data.messages.length !== 100) {
chan.find(".show-more").removeClass("show"); chan.find(".show-more").removeClass("show");
} }
}); });
@ -274,7 +275,7 @@ $(function() {
}); });
if (next !== null) { if (next !== null) {
var id = next.data("id"); id = next.data("id");
sidebar.find("[data-id=" + id + "]").click(); sidebar.find("[data-id=" + id + "]").click();
} else { } else {
sidebar.find(".chan") sidebar.find(".chan")
@ -374,7 +375,7 @@ $(function() {
].indexOf(name) !== -1) { ].indexOf(name) !== -1) {
chat.toggleClass("hide-" + name, !self.prop("checked")); chat.toggleClass("hide-" + name, !self.prop("checked"));
} }
if (name == "colors") { if (name === "colors") {
chat.toggleClass("no-colors", !self.prop("checked")); chat.toggleClass("no-colors", !self.prop("checked"));
} }
}).find("input") }).find("input")
@ -383,7 +384,7 @@ $(function() {
$("#badge").on("change", function() { $("#badge").on("change", function() {
var self = $(this); var self = $(this);
if (self.prop("checked")) { if (self.prop("checked")) {
if (Notification.permission != "granted") { if (Notification.permission !== "granted") {
Notification.requestPermission(); Notification.requestPermission();
} }
} }
@ -407,7 +408,6 @@ $(function() {
.tab(complete, {hint: false}); .tab(complete, {hint: false});
var form = $("#form"); var form = $("#form");
var submit = $("#submit");
form.on("submit", function(e) { form.on("submit", function(e) {
e.preventDefault(); e.preventDefault();
@ -428,7 +428,7 @@ $(function() {
var text = ""; var text = "";
if (window.getSelection) { if (window.getSelection) {
text = window.getSelection().toString(); text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") { } else if (document.selection && document.selection.type !== "Control") {
text = document.selection.createRange().text; text = document.selection.createRange().text;
} }
if (!text) { if (!text) {
@ -580,7 +580,7 @@ $(function() {
pop.play(); pop.play();
} }
favico.badge("!"); favico.badge("!");
if (settings.badge && Notification.permission == "granted") { if (settings.badge && Notification.permission === "granted") {
var notify = new Notification(msg.from + " says:", { var notify = new Notification(msg.from + " says:", {
body: msg.text.trim(), body: msg.text.trim(),
icon: "/img/logo-64.png" icon: "/img/logo-64.png"
@ -640,7 +640,7 @@ $(function() {
var content = self.parent().next(".toggle-content"); var content = self.parent().next(".toggle-content");
if (bottom && !content.hasClass("show")) { if (bottom && !content.hasClass("show")) {
var img = content.find("img"); var img = content.find("img");
if (img.length != 0 && !img.width()) { if (img.length !== 0 && !img.width()) {
img.on("load", function() { img.on("load", function() {
chat.scrollBottom(); chat.scrollBottom();
}); });
@ -678,7 +678,7 @@ $(function() {
form.find(".btn") form.find(".btn")
.attr("disabled", true) .attr("disabled", true)
.end(); .end();
if (form.closest(".window").attr("id") == "connect") { if (form.closest(".window").attr("id") === "connect") {
event = "conn"; event = "conn";
} }
var values = {}; var values = {};
@ -732,8 +732,8 @@ $(function() {
Mousetrap.bind([ Mousetrap.bind([
"command+k", "command+k",
"ctrl+shift+l" "ctrl+shift+l"
], function (e) { ], function(e) {
if(e.target === input[0]) { if (e.target === input[0]) {
clear(); clear();
e.preventDefault(); e.preventDefault();
} }
@ -771,7 +771,7 @@ $(function() {
words.push(nicks[i]); words.push(nicks[i]);
} }
var channels = sidebar.find(".chan") sidebar.find(".chan")
.each(function() { .each(function() {
var self = $(this); var self = $(this);
if (!self.hasClass("lobby")) { if (!self.hasClass("lobby")) {
@ -875,7 +875,7 @@ $(function() {
} }
array.splice(new_index, 0, array.splice(old_index, 1)[0]); array.splice(new_index, 0, array.splice(old_index, 1)[0]);
return array; return array;
}; }
document.addEventListener( document.addEventListener(
"visibilitychange", "visibilitychange",

View File

@ -1,3 +1,3 @@
#!/usr/bin/env node #!/usr/bin/env node
process.chdir(__dirname); process.chdir(__dirname);
var cli = require("./src/command-line"); require("./src/command-line");

View File

@ -80,11 +80,11 @@ Client.prototype.emit = function(event, data) {
} }
var config = this.config || {}; var config = this.config || {};
if (config.log === true) { if (config.log === true) {
if (event == "msg") { if (event === "msg") {
var target = this.find(data.chan); var target = this.find(data.chan);
if (target) { if (target) {
var chan = target.chan.name; var chan = target.chan.name;
if (target.chan.type == Chan.Type.LOBBY) { if (target.chan.type === Chan.Type.LOBBY) {
chan = target.network.host; chan = target.network.host;
} }
log.write( log.write(
@ -131,7 +131,7 @@ Client.prototype.connect = function(args) {
if (config.bind) { if (config.bind) {
server.localAddress = config.bind; server.localAddress = config.bind;
if(args.tls) { if (args.tls) {
var socket = net.connect(server); var socket = net.connect(server);
server.socket = socket; server.socket = socket;
} }
@ -152,7 +152,7 @@ Client.prototype.connect = function(args) {
}); });
var nick = args.nick || "shout-user"; var nick = args.nick || "shout-user";
var username = args.username || nick.replace(/[^a-zA-Z0-9]/g, ''); var username = args.username || nick.replace(/[^a-zA-Z0-9]/g, "");
var realname = args.realname || "Shout User"; var realname = args.realname || "Shout User";
var irc = slate(stream); var irc = slate(stream);
@ -273,10 +273,10 @@ Client.prototype.sort = function(data) {
var type = data.type; var type = data.type;
var order = data.order || []; var order = data.order || [];
var sorted = [];
switch (type) { switch (type) {
case "networks": case "networks":
var sorted = [];
_.each(order, function(i) { _.each(order, function(i) {
var find = _.find(self.networks, {id: i}); var find = _.find(self.networks, {id: i});
if (find) { if (find) {
@ -292,7 +292,6 @@ Client.prototype.sort = function(data) {
if (!network) { if (!network) {
return; return;
} }
var sorted = [];
_.each(order, function(i) { _.each(order, function(i) {
var find = _.find(network.channels, {id: i}); var find = _.find(network.channels, {id: i});
if (find) { if (find) {
@ -328,7 +327,7 @@ Client.prototype.save = function(force) {
var client = this; var client = this;
var config = Helper.getConfig(); var config = Helper.getConfig();
if(config.public) { if (config.public) {
return; return;
} }
@ -360,7 +359,7 @@ Client.prototype.save = function(force) {
try { try {
json = JSON.parse(data); json = JSON.parse(data);
json.networks = networks; json.networks = networks;
} catch(e) { } catch (e) {
console.log(e); console.log(e);
return; return;
} }

View File

@ -3,7 +3,6 @@ var fs = require("fs");
var Client = require("./client"); var Client = require("./client");
var mkdirp = require("mkdirp"); var mkdirp = require("mkdirp");
var Helper = require("./helper"); var Helper = require("./helper");
var moment = require("moment");
module.exports = ClientManager; module.exports = ClientManager;
@ -14,7 +13,7 @@ function ClientManager() {
ClientManager.prototype.findClient = function(name) { ClientManager.prototype.findClient = function(name) {
for (var i in this.clients) { for (var i in this.clients) {
var client = this.clients[i]; var client = this.clients[i];
if (client.name == name) { if (client.name === name) {
return client; return client;
} }
} }
@ -35,7 +34,7 @@ ClientManager.prototype.loadUser = function(name) {
"utf-8" "utf-8"
); );
json = JSON.parse(json); json = JSON.parse(json);
} catch(e) { } catch (e) {
console.log(e); console.log(e);
return; return;
} }
@ -62,7 +61,7 @@ ClientManager.prototype.getUsers = function() {
users.push(file.replace(".json", "")); users.push(file.replace(".json", ""));
} }
}); });
} catch(e) { } catch (e) {
console.log(e); console.log(e);
return; return;
} }
@ -88,7 +87,7 @@ ClientManager.prototype.addUser = function(name, password) {
JSON.stringify(user, null, " "), JSON.stringify(user, null, " "),
{mode: "0777"} {mode: "0777"}
); );
} catch(e) { } catch (e) {
throw e; throw e;
} }
return true; return true;
@ -102,15 +101,14 @@ ClientManager.prototype.removeUser = function(name) {
try { try {
var path = Helper.HOME + "/users/" + name + ".json"; var path = Helper.HOME + "/users/" + name + ".json";
fs.unlinkSync(path); fs.unlinkSync(path);
} catch(e) { } catch (e) {
throw e; throw e;
} }
return true; return true;
}; };
ClientManager.prototype.autoload = function(sockets) { ClientManager.prototype.autoload = function(/* sockets */) {
var self = this; var self = this;
var loaded = [];
setInterval(function() { setInterval(function() {
var loaded = _.pluck( var loaded = _.pluck(
self.clients, self.clients,

View File

@ -8,7 +8,7 @@ var Helper = require("../helper");
program program
.command("add <name>") .command("add <name>")
.description("Add a new user") .description("Add a new user")
.action(function(name, password) { .action(function(name/* , password */) {
var path = Helper.HOME + "/users"; var path = Helper.HOME + "/users";
try { try {
mkdirp.sync(path); mkdirp.sync(path);

View File

@ -1,7 +1,4 @@
var fs = require("fs");
var path = require("path");
var program = require("commander"); var program = require("commander");
var mkdirp = require("mkdirp");
var child = require("child_process"); var child = require("child_process");
var Helper = require("../helper"); var Helper = require("../helper");

View File

@ -1,4 +1,3 @@
var _ = require("lodash");
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var program = require("commander"); var program = require("commander");
var shout = require("../server"); var shout = require("../server");

View File

@ -7,4 +7,4 @@ module.exports = {
function getConfig() { function getConfig() {
return require(path.resolve(this.HOME) + "/config"); return require(path.resolve(this.HOME) + "/config");
}; }

View File

@ -4,7 +4,7 @@ var net = require("net");
var users = {}; var users = {};
module.exports.start = function(port) { module.exports.start = function(port) {
var server = net.createServer(init).listen(port || 113); net.createServer(init).listen(port || 113);
}; };
module.exports.hook = function(stream, user) { module.exports.hook = function(stream, user) {

View File

@ -7,7 +7,7 @@ module.exports.write = function(user, network, chan, msg) {
try { try {
var path = Helper.HOME + "/logs/" + user + "/" + network; var path = Helper.HOME + "/logs/" + user + "/" + network;
mkdirp.sync(path); mkdirp.sync(path);
} catch(e) { } catch (e) {
console.log(e); console.log(e);
return; return;
} }
@ -20,7 +20,7 @@ module.exports.write = function(user, network, chan, msg) {
var line = "[" + time + "] "; var line = "[" + time + "] ";
var type = msg.type.trim(); var type = msg.type.trim();
if (type == "message" || type == "highlight") { if (type === "message" || type === "highlight") {
// Format: // Format:
// [2014-01-01 00:00:00] <Arnold> Put that cookie down.. Now!! // [2014-01-01 00:00:00] <Arnold> Put that cookie down.. Now!!
line += "<" + msg.from + "> " + msg.text; line += "<" + msg.from + "> " + msg.text;
@ -38,7 +38,7 @@ module.exports.write = function(user, network, chan, msg) {
line + "\n", line + "\n",
function(e) { function(e) {
if (e) { if (e) {
console.log("Log#write():\n" + e) console.log("Log#write():\n" + e);
} }
} }
); );

View File

@ -37,7 +37,7 @@ Chan.prototype.sortUsers = function() {
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);
}; };

View File

@ -1,7 +1,7 @@
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;
} }

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,5 +1,5 @@
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;

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,5 +1,5 @@
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;
@ -7,13 +7,13 @@ module.exports = function(network, chan, cmd, args) {
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;

View File

@ -1,16 +1,15 @@
var _ = require("lodash"); var _ = require("lodash");
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 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;

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,5 +1,5 @@
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;

View File

@ -1,11 +1,11 @@
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

View File

@ -1,7 +1,7 @@
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;
} }

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,7 +1,7 @@
var _ = require("lodash"); var _ = require("lodash");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "ns" && cmd != "cs" && cmd != "hs") { if (cmd !== "ns" && cmd !== "cs" && cmd !== "hs") {
return; return;
} }
var target = ({ var target = ({

View File

@ -1,5 +1,5 @@
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd != "topic") { if (cmd !== "topic") {
return; return;
} }

View File

@ -1,5 +1,5 @@
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) {

View File

@ -1,6 +1,6 @@
var pkg = require(process.cwd() + "/package.json"); var pkg = require(process.cwd() + "/package.json");
module.exports = function(irc, network) { module.exports = function(irc/* , network */) {
irc.on("message", function(data) { irc.on("message", function(data) {
if (data.message.indexOf("\001") !== 0) { if (data.message.indexOf("\001") !== 0) {
return; return;
@ -15,7 +15,7 @@ module.exports = function(irc, network) {
); );
break; break;
case "PING": case "PING":
if (split.length == 2) { if (split.length === 2) {
irc.ctcp(data.from, "PING " + split[1]); irc.ctcp(data.from, "PING " + split[1]);
} }
break; break;

View File

@ -13,7 +13,7 @@ module.exports = function(irc, network) {
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

@ -26,7 +26,7 @@ module.exports = function(irc, network) {
users: users users: users
}); });
var self = false; var self = false;
if (data.nick.toLowerCase() == irc.me.toLowerCase()) { if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
self = true; self = true;
} }
var msg = new Msg({ var msg = new Msg({

View File

@ -12,7 +12,7 @@ module.exports = function(irc, network) {
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}));
@ -24,7 +24,7 @@ module.exports = function(irc, network) {
}); });
var self = false; var self = false;
if (data.nick.toLowerCase() == irc.me.toLowerCase()) { if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
self = true; self = true;
} }

View File

@ -3,7 +3,7 @@ var cheerio = require("cheerio");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
var request = require("request"); var request = require("request");
var Helper = require("../../helper"); var Helper = require("../../helper");
var es = require('event-stream'); var es = require("event-stream");
process.setMaxListeners(0); process.setMaxListeners(0);
@ -28,7 +28,7 @@ module.exports = function(irc, network) {
return; return;
} }
var self = data.to.toLowerCase() == irc.me.toLowerCase(); var self = data.to.toLowerCase() === irc.me.toLowerCase();
var chan = _.findWhere(network.channels, {name: self ? data.from : data.to}); var chan = _.findWhere(network.channels, {name: self ? data.from : data.to});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
@ -67,12 +67,12 @@ function parse(msg, url, res, client) {
toggle.type = "link"; toggle.type = "link";
toggle.head = $("title").text(); toggle.head = $("title").text();
toggle.body = toggle.body =
$('meta[name=description]').attr('content') $("meta[name=description]").attr("content")
|| $('meta[property="og:description"]').attr('content') || $("meta[property=\"og:description\"]").attr("content")
|| "No description found."; || "No description found.";
toggle.thumb = toggle.thumb =
$('meta[property="og:image"]').attr('content') $("meta[property=\"og:image\"]").attr("content")
|| $('meta[name="twitter:image:src"]').attr('content') || $("meta[name=\"twitter:image:src\"]").attr("content")
|| ""; || "";
break; break;
@ -93,18 +93,18 @@ function parse(msg, url, res, client) {
function fetch(url, cb) { function fetch(url, cb) {
try { try {
var req = request.get(url); var req = request.get(url);
} catch(e) { } catch (e) {
return; return;
} }
var length = 0; var length = 0;
var limit = 1024 * 10; var limit = 1024 * 10;
req req
.on('response', function(res) { .on("response", function(res) {
if (!(/(text\/html|application\/json)/.test(res.headers['content-type']))) { if (!(/(text\/html|application\/json)/.test(res.headers["content-type"]))) {
res.req.abort(); res.req.abort();
} }
}) })
.on('error', function() {}) .on("error", function() {})
.pipe(es.map(function(data, next) { .pipe(es.map(function(data, next) {
length += data.length; length += data.length;
if (length > limit) { if (length > limit) {
@ -118,12 +118,12 @@ function fetch(url, cb) {
var type; var type;
try { try {
body = JSON.parse(data); body = JSON.parse(data);
} catch(e) { } catch (e) {
body = {}; body = {};
} }
try { try {
type = req.response.headers['content-type'].split(/ *; */).shift(); type = req.response.headers["content-type"].split(/ *; */).shift();
} catch(e) { } catch (e) {
type = {}; type = {};
} }
data = { data = {

View File

@ -5,13 +5,13 @@ 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) {
if (data.message.indexOf("\u0001") === 0 && data.message.substring(0, 7) != "\u0001ACTION") { if (data.message.indexOf("\u0001") === 0 && data.message.substring(0, 7) !== "\u0001ACTION") {
// Hide ctcp messages. // Hide ctcp messages.
return; return;
} }
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;
} }
@ -40,11 +40,11 @@ module.exports = function(irc, network) {
}); });
var self = false; var self = false;
if (data.from.toLowerCase() == irc.me.toLowerCase()) { if (data.from.toLowerCase() === irc.me.toLowerCase()) {
self = true; self = true;
} }
if (chan.id != client.activeChannel) { if (chan.id !== client.activeChannel) {
chan.unread++; chan.unread++;
} }

View File

@ -14,7 +14,7 @@ module.exports = function(irc, network) {
from = data.target; from = data.target;
} }
var self = false; var self = false;
if (from.toLowerCase() == irc.me.toLowerCase()) { if (from.toLowerCase() === irc.me.toLowerCase()) {
self = true; self = true;
} }
var msg = new Msg({ var msg = new Msg({

View File

@ -6,7 +6,7 @@ module.exports = function(irc, network) {
irc.on("nick", function(data) { irc.on("nick", function(data) {
var self = false; var self = false;
var nick = data["new"]; var nick = data["new"];
if (nick == irc.me) { if (nick === 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 " + nick, text: "You're now known as " + nick,

View File

@ -5,7 +5,7 @@ module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("notice", function(data) { irc.on("notice", 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;
} }
@ -15,7 +15,7 @@ module.exports = function(irc, network) {
} }
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({

View File

@ -9,7 +9,7 @@ module.exports = function(irc, network) {
return; return;
} }
var from = data.nick; var from = data.nick;
if (from == irc.me) { if (from === irc.me) {
network.channels = _.without(network.channels, chan); network.channels = _.without(network.channels, chan);
client.save(); client.save();
client.emit("part", { client.emit("part", {

View File

@ -26,7 +26,6 @@ module.exports = function(irc, network) {
channels: "on", channels: "on",
server: "using" server: "using"
}; };
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() === "") {

View File

@ -26,7 +26,7 @@ module.exports = function(options) {
var protocol = https.enable ? "https" : "http"; var protocol = https.enable ? "https" : "http";
var port = config.port; var port = config.port;
var host = config.host; var host = config.host;
var transports = config.transports || ['websocket', 'polling']; var transports = config.transports || ["websocket", "polling"];
if (!https.enable){ if (!https.enable){
server = require("http"); server = require("http");
@ -36,7 +36,7 @@ module.exports = function(options) {
server = server.createServer({ server = server.createServer({
key: fs.readFileSync(https.key), key: fs.readFileSync(https.key),
cert: fs.readFileSync(https.certificate) cert: fs.readFileSync(https.certificate)
}, app).listen(port, host) }, app).listen(port, host);
} }
if ((config.identd || {}).enable) { if ((config.identd || {}).enable) {
@ -71,7 +71,7 @@ module.exports = function(options) {
}; };
function index(req, res, next) { function index(req, res, next) {
if (req.url.split("?")[0] != "/") return next(); if (req.url.split("?")[0] !== "/") return next();
return fs.readFile("client/index.html", "utf-8", function(err, file) { return fs.readFile("client/index.html", "utf-8", function(err, file) {
var data = _.merge( var data = _.merge(
require("../package.json"), require("../package.json"),
@ -144,10 +144,10 @@ function auth(data) {
var success = false; var success = false;
_.each(manager.clients, function(client) { _.each(manager.clients, function(client) {
if (data.token) { if (data.token) {
if (data.token == client.token) { if (data.token === client.token) {
success = true; success = true;
} }
} else if (client.config.user == data.user) { } else if (client.config.user === data.user) {
if (bcrypt.compareSync(data.password || "", client.config.password)) { if (bcrypt.compareSync(data.password || "", client.config.password)) {
success = true; success = true;
} }

View File

@ -1,37 +1,37 @@
var assert = require('assert'); var assert = require("assert");
var util = require('../util'); var util = require("../util");
var link = require('../../src/plugins/irc-events/link.js'); var link = require("../../src/plugins/irc-events/link.js");
describe('Link plugin', function() { describe("Link plugin", function() {
before(function(done) { before(function(done) {
this.app = util.createWebserver(); this.app = util.createWebserver();
this.connection = this.app.listen(9002, done); this.connection = this.app.listen(9002, done);
}); });
after(function(done) { after(function(done) {
this.connection.close(done); this.connection.close(done);
}); });
beforeEach(function() { beforeEach(function() {
this.irc = util.createClient(); this.irc = util.createClient();
this.network = util.createNetwork(); this.network = util.createNetwork();
}); });
it('should be able to fetch basic information about URLs', function(done) { it("should be able to fetch basic information about URLs", function(done) {
var plugin = link.call(this.irc, this.irc, this.network); link.call(this.irc, this.irc, this.network);
this.app.get('/basic', function(req, res) { this.app.get("/basic", function(req, res) {
res.send('<title>test</title>'); res.send("<title>test</title>");
}); });
this.irc.createMessage({ this.irc.createMessage({
message: 'http://localhost:9002/basic' message: "http://localhost:9002/basic"
}); });
this.irc.once('toggle', function(data) { this.irc.once("toggle", function(data) {
assert.equal(data.head, 'test'); assert.equal(data.head, "test");
done(); done();
}) });
}); });
}); });

View File

@ -1,43 +1,41 @@
var EventEmitter = require('events').EventEmitter; var EventEmitter = require("events").EventEmitter;
var util = require('util'); var util = require("util");
var _ = require('lodash'); var _ = require("lodash");
var express = require('express'); var express = require("express");
function MockClient(opts) { function MockClient(opts) {
this.me = 'test-user'; this.me = "test-user";
for(k in opts) { for (var k in opts) {
this[k] = opts[k]; this[k] = opts[k];
} }
} }
util.inherits(MockClient, EventEmitter); util.inherits(MockClient, EventEmitter);
MockClient.prototype.createMessage = function(opts) { MockClient.prototype.createMessage = function(opts) {
var message = _.extend({ var message = _.extend({
message: 'dummy message', message: "dummy message",
from: 'test-user', from: "test-user",
to: 'test-channel' to: "test-channel"
}, opts); }, opts);
this.emit('message', message); this.emit("message", message);
} };
module.exports = { module.exports = {
createClient: function() { createClient: function() {
return new MockClient(); return new MockClient();
}, },
createNetwork: function() { createNetwork: function() {
return { return {
channels: [{ channels: [{
name: 'test-channel', name: "test-channel",
messages: [] messages: []
}] }]
} };
}, },
createWebserver: function() { createWebserver: function() {
return express(); return express();
} }
} };