Merge pull request #1962 from thelounge/xpaw/no-var

Enable no-var rule
This commit is contained in:
Pavel Djundik 2018-02-19 20:12:31 +02:00 committed by GitHub
commit c97352905d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 260 additions and 265 deletions

View File

@ -45,6 +45,7 @@ rules:
no-useless-constructor: error
no-useless-return: error
no-use-before-define: [error, {functions: false}]
no-var: error
object-curly-spacing: [error, never]
padded-blocks: [error, never]
prefer-const: error

View File

@ -2,8 +2,8 @@
// Generates a string from "color-1" to "color-32" based on an input string
module.exports = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash += str.charCodeAt(i);
}

View File

@ -1,6 +1,6 @@
"use strict";
var diff;
let diff;
module.exports = function(a, opt) {
if (a !== diff) {

View File

@ -1,7 +1,6 @@
"use strict";
module.exports = function(mode) {
var modes = {
const modes = {
"~": "owner",
"&": "admin",
"!": "admin",
@ -10,5 +9,7 @@ module.exports = function(mode) {
"+": "voice",
"": "normal",
};
module.exports = function(mode) {
return modes[mode];
};

View File

@ -4,12 +4,12 @@
* Simple slideout menu implementation.
*/
module.exports = function slideoutMenu(viewport, menu) {
var touchStartPos = null;
var touchCurPos = null;
var touchStartTime = 0;
var menuWidth = 0;
var menuIsOpen = false;
var menuIsMoving = false;
let touchStartPos = null;
let touchCurPos = null;
let touchStartTime = 0;
let menuWidth = 0;
let menuIsOpen = false;
let menuIsMoving = false;
function toggleMenu(state) {
menuIsOpen = state;
@ -26,7 +26,7 @@ module.exports = function slideoutMenu(viewport, menu) {
return;
}
var touch = e.touches.item(0);
const touch = e.touches.item(0);
viewport.classList.toggle("menu-dragging", true);
menuWidth = parseFloat(window.getComputedStyle(menu).width);
@ -42,8 +42,8 @@ module.exports = function slideoutMenu(viewport, menu) {
}
function onTouchMove(e) {
var touch = touchCurPos = e.touches.item(0);
var setX = touch.screenX - touchStartPos.screenX;
const touch = touchCurPos = e.touches.item(0);
let setX = touch.screenX - touchStartPos.screenX;
if (Math.abs(setX > 30)) {
menuIsMoving = true;
@ -73,8 +73,8 @@ module.exports = function slideoutMenu(viewport, menu) {
}
function onTouchEnd() {
var diff = touchCurPos.screenX - touchStartPos.screenX;
var absDiff = Math.abs(diff);
const diff = touchCurPos.screenX - touchStartPos.screenX;
const absDiff = Math.abs(diff);
if (absDiff > menuWidth / 2 || Date.now() - touchStartTime < 180 && absDiff > 50) {
toggleMenu(diff > 0);

View File

@ -1,4 +1,4 @@
/* eslint strict: 0 */
/* eslint strict: 0, no-var: 0 */
"use strict";
/*

View File

@ -24,15 +24,15 @@ const Changelog = require("./socket-events/changelog");
const JoinChannel = require("./join-channel");
$(function() {
var sidebar = $("#sidebar, #footer");
var chat = $("#chat");
const sidebar = $("#sidebar, #footer");
const chat = $("#chat");
$(document.body).data("app-name", document.title);
var viewport = $("#viewport");
var sidebarSlide = slideoutMenu(viewport[0], sidebar[0]);
var contextMenuContainer = $("#context-menu-container");
var contextMenu = $("#context-menu");
const viewport = $("#viewport");
const sidebarSlide = slideoutMenu(viewport[0], sidebar[0]);
const contextMenuContainer = $("#context-menu-container");
const contextMenu = $("#context-menu");
$("#main").on("click", function(e) {
if ($(e.target).is(".lt")) {
@ -43,16 +43,16 @@ $(function() {
});
viewport.on("click", ".rt", function(e) {
var self = $(this);
const self = $(this);
viewport.toggleClass(self.prop("class"));
e.stopPropagation();
chat.find(".chan.active .chat").trigger("msg.sticky");
});
function positionContextMenu(that, e) {
var offset;
var menuWidth = contextMenu.outerWidth();
var menuHeight = contextMenu.outerHeight();
let offset;
const menuWidth = contextMenu.outerWidth();
const menuHeight = contextMenu.outerHeight();
if (that.hasClass("menu")) {
offset = that.offset();
@ -75,8 +75,8 @@ $(function() {
}
function showContextMenu(that, e) {
var target = $(e.currentTarget);
var output = "";
const target = $(e.currentTarget);
let output = "";
if (target.hasClass("user")) {
output = templates.contextmenu_item({
@ -193,10 +193,10 @@ $(function() {
input.style.height = input.style.minHeight;
}
var input = $("#input")
const input = $("#input")
.history()
.on("input", function() {
var style = window.getComputedStyle(this);
const style = window.getComputedStyle(this);
// Start by resetting height before computing as scrollHeight does not
// decrease when deleting characters
@ -212,7 +212,7 @@ $(function() {
chat.find(".chan.active .chat").trigger("msg.sticky"); // fix growing
});
var focus = $.noop;
let focus = $.noop;
if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) {
focus = function() {
if (chat.find(".active").hasClass("chan")) {
@ -238,7 +238,7 @@ $(function() {
$("#form").on("submit", function(e) {
e.preventDefault();
utils.forceFocus();
var text = input.val();
const text = input.val();
if (text.length === 0) {
return;
@ -265,11 +265,11 @@ $(function() {
utils.toggleNickEditor(true);
// Selects existing nick in the editable text field
var element = document.querySelector("#nick-value");
const element = document.querySelector("#nick-value");
element.focus();
var range = document.createRange();
const range = document.createRange();
range.selectNodeContents(element);
var selection = window.getSelection();
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
});
@ -278,7 +278,7 @@ $(function() {
$("button#submit-nick").on("click", submitNick);
function submitNick() {
var newNick = $("#nick-value").text().trim();
const newNick = $("#nick-value").text().trim();
if (newNick.length === 0) {
cancelNick();
@ -316,8 +316,8 @@ $(function() {
});
chat.on("click", ".inline-channel", function() {
var name = $(this).data("chan");
var chan = utils.findCurrentNetworkChan(name);
const name = $(this).data("chan");
const chan = utils.findCurrentNetworkChan(name);
if (chan.length) {
chan.trigger("click");
@ -334,8 +334,8 @@ $(function() {
});
const openWindow = function openWindow(e, data) {
var self = $(this);
var target = self.data("target");
const self = $(this);
const target = self.data("target");
if (!target) {
return;
}
@ -372,9 +372,7 @@ $(function() {
sidebarSlide.toggle(false);
}
var lastActive = $("#windows > .active");
lastActive
const lastActive = $("#windows > .active")
.removeClass("active")
.find(".chat")
.unsticky();
@ -391,7 +389,7 @@ $(function() {
render.trimMessageInChannel(lastActiveChan, 100);
}
var chan = $(target)
const chan = $(target)
.addClass("active")
.trigger("show");
@ -403,7 +401,7 @@ $(function() {
document.title = title;
const type = chan.data("type");
var placeholder = "";
let placeholder = "";
if (type === "channel" || type === "query") {
placeholder = `Write to ${chanTitle}`;
}
@ -417,7 +415,7 @@ $(function() {
utils.setNick(self.closest(".network").data("nick"));
}
var chanChat = chan.find(".chat");
const chanChat = chan.find(".chat");
if (chanChat.length > 0 && type !== "special") {
chanChat.sticky();
}
@ -481,11 +479,11 @@ $(function() {
});
function closeChan(chan) {
var cmd = "/close";
let cmd = "/close";
if (chan.hasClass("lobby")) {
cmd = "/quit";
var server = chan.find(".name").html();
const server = chan.find(".name").html();
if (!confirm("Disconnect from " + server + "?")) { // eslint-disable-line no-alert
return false;
}
@ -601,17 +599,16 @@ $(function() {
if ($("body").hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) {
$("#connect").one("show", function() {
var params = URI(document.location.search);
params = params.search(true);
const params = URI(document.location.search).search(true);
// Possible parameters: name, host, port, password, tls, nick, username, realname, join
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only
for (var key in params) {
for (let key in params) {
if (params.hasOwnProperty(key)) {
var value = params[key];
const value = params[key];
// \W searches for non-word characters
key = key.replace(/\W/g, "");
var element = $("#connect input[name='" + key + "']");
const element = $("#connect input[name='" + key + "']");
// if the element exists, it isn't disabled, and it isn't hidden
if (element.length > 0 && !element.is(":disabled") && !element.is(":hidden")) {
if (element.is(":checkbox")) {

View File

@ -55,7 +55,7 @@ module.exports.initialize = () => {
const settings = $("#settings");
for (var i in options) {
for (const i in options) {
if (i === "userStyles") {
settings.find("#user-specified-css-input").val(options[i]);
} else if (i === "highlights") {
@ -137,8 +137,7 @@ module.exports.initialize = () => {
} else if (name === "userStyles") {
userStyles.html(options[name]);
} else if (name === "highlights") {
var highlightString = options[name];
options.highlights = highlightString.split(",").map(function(h) {
options.highlights = options[name].split(",").map(function(h) {
return h.trim();
}).filter(function(h) {
// Ensure we don't have empty string in the list of highlights

View File

@ -276,7 +276,7 @@ function loadMoreHistory(entries) {
return;
}
var target = $(entry.target).find(".show-more-button");
const target = $(entry.target).find(".show-more-button");
if (target.prop("disabled")) {
return;

View File

@ -68,7 +68,7 @@ function processReceivedMessage(data) {
notifyMessage(targetId, channel, data);
var lastVisible = container.find("div:visible").last();
const lastVisible = container.find("div:visible").last();
if (data.msg.self
|| lastVisible.hasClass("unread-marker")
|| (lastVisible.hasClass("date-marker")

View File

@ -4,8 +4,8 @@ const $ = require("jquery");
const escape = require("css.escape");
const input = $("#input");
var serverHash = -1;
var lastMessageId = -1;
var serverHash = -1; // eslint-disable-line no-var
var lastMessageId = -1; // eslint-disable-line no-var
module.exports = {
inputCommands: {collapse, expand, join},
@ -92,7 +92,7 @@ const favicon = $("#favicon");
function toggleNotificationMarkers(newState) {
// Toggles the favicon to red when there are unread notifications
if (favicon.data("toggled") !== newState) {
var old = favicon.prop("href");
const old = favicon.prop("href");
favicon.prop("href", favicon.data("other"));
favicon.data("other", old);
favicon.data("toggled", newState);

View File

@ -8,7 +8,7 @@ process.chdir(__dirname);
// Doing this check as soon as possible allows us to avoid ES6 parser errors or
// other issues
// Try to display messages nicely, but gracefully degrade if anything goes wrong
var pkg = require("./package.json");
const pkg = require("./package.json");
if (!require("semver").satisfies(process.version, pkg.engines.node)) {
let colors;
let log;

View File

@ -1,20 +1,20 @@
"use strict";
var _ = require("lodash");
var colors = require("colors/safe");
var pkg = require("../package.json");
var Chan = require("./models/chan");
var crypto = require("crypto");
var Msg = require("./models/msg");
var Network = require("./models/network");
var ircFramework = require("irc-framework");
var Helper = require("./helper");
const _ = require("lodash");
const colors = require("colors/safe");
const pkg = require("../package.json");
const Chan = require("./models/chan");
const crypto = require("crypto");
const Msg = require("./models/msg");
const Network = require("./models/network");
const ircFramework = require("irc-framework");
const Helper = require("./helper");
const UAParser = require("ua-parser-js");
module.exports = Client;
var id = 0;
var events = [
let id = 0;
const events = [
"away",
"connection",
"unhandled",
@ -37,7 +37,7 @@ var events = [
"list",
"whois",
];
var inputs = [
const inputs = [
"ban",
"ctcp",
"msg",
@ -59,8 +59,7 @@ var inputs = [
"list",
"whois",
].reduce(function(plugins, name) {
var path = "./plugins/inputs/" + name;
var plugin = require(path);
const plugin = require(`./plugins/inputs/${name}`);
plugin.commands.forEach((command) => plugins[command] = plugin);
return plugins;
}, {});
@ -78,9 +77,9 @@ function Client(manager, name, config = {}) {
manager: manager,
});
var client = this;
const client = this;
var delay = 0;
let delay = 0;
(client.config.networks || []).forEach((n) => {
setTimeout(function() {
client.connect(n);
@ -114,10 +113,10 @@ Client.prototype.emit = function(event, data) {
};
Client.prototype.find = function(channelId) {
var network = null;
var chan = null;
for (var i in this.networks) {
var n = this.networks[i];
let network = null;
let chan = null;
for (const i in this.networks) {
const n = this.networks[i];
chan = _.find(n.channels, {id: channelId});
if (chan) {
network = n;
@ -135,15 +134,13 @@ Client.prototype.find = function(channelId) {
};
Client.prototype.connect = function(args) {
var config = Helper.config;
var client = this;
var nick = args.nick || "lounge-user";
var webirc = null;
var channels = [];
const client = this;
const nick = args.nick || "lounge-user";
let webirc = null;
let channels = [];
if (args.channels) {
var badName = false;
let badName = false;
args.channels.forEach((chan) => {
if (!chan.name) {
@ -177,8 +174,8 @@ Client.prototype.connect = function(args) {
args.ip = args.ip || (client.config && client.config.ip) || client.ip;
args.hostname = args.hostname || (client.config && client.config.hostname) || client.hostname;
var network = new Network({
name: args.name || (config.displayNetwork ? "" : config.defaults.name) || "",
const network = new Network({
name: args.name || (Helper.config.displayNetwork ? "" : Helper.config.defaults.name) || "",
host: args.host || "",
port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),
tls: !!args.tls,
@ -197,9 +194,9 @@ Client.prototype.connect = function(args) {
networks: [network.getFilteredClone(this.lastActiveChannel, -1)],
});
if (config.lockNetwork) {
if (Helper.config.lockNetwork) {
// This check is needed to prevent invalid user configurations
if (!Helper.config.public && args.host && args.host.length > 0 && args.host !== config.defaults.host) {
if (!Helper.config.public && args.host && args.host.length > 0 && args.host !== Helper.config.defaults.host) {
network.channels[0].pushMessage(client, new Msg({
type: Msg.Type.ERROR,
text: "Hostname you specified is not allowed.",
@ -207,9 +204,9 @@ Client.prototype.connect = function(args) {
return;
}
network.host = config.defaults.host;
network.port = config.defaults.port;
network.tls = config.defaults.tls;
network.host = Helper.config.defaults.host;
network.port = Helper.config.defaults.port;
network.tls = Helper.config.defaults.tls;
}
if (network.host.length === 0) {
@ -220,17 +217,17 @@ Client.prototype.connect = function(args) {
return;
}
if (config.webirc && network.host in config.webirc) {
if (Helper.config.webirc && network.host in Helper.config.webirc) {
if (!args.hostname) {
args.hostname = args.ip;
}
if (args.ip) {
if (config.webirc[network.host] instanceof Function) {
webirc = config.webirc[network.host](client, args);
if (Helper.config.webirc[network.host] instanceof Function) {
webirc = Helper.config.webirc[network.host](client, args);
} else {
webirc = {
password: config.webirc[network.host],
password: Helper.config.webirc[network.host],
username: pkg.name,
address: args.ip,
hostname: args.hostname,
@ -247,11 +244,11 @@ Client.prototype.connect = function(args) {
host: network.host,
port: network.port,
nick: nick,
username: config.useHexIp ? Helper.ip2hex(args.ip) : network.username,
username: Helper.config.useHexIp ? Helper.ip2hex(args.ip) : network.username,
gecos: network.realname,
password: network.password,
tls: network.tls,
outgoing_addr: config.bind,
outgoing_addr: Helper.config.bind,
rejectUnauthorized: false,
enable_chghost: true,
enable_echomessage: true,
@ -266,8 +263,7 @@ Client.prototype.connect = function(args) {
]);
events.forEach((plugin) => {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
require(`./plugins/irc-events/${plugin}`).apply(client, [
network.irc,
network,
]);
@ -319,7 +315,7 @@ Client.prototype.updateSession = function(token, ip, request) {
};
Client.prototype.setPassword = function(hash, callback) {
var client = this;
const client = this;
client.manager.updateUser(client.name, {
password: hash,
@ -334,7 +330,7 @@ Client.prototype.setPassword = function(hash, callback) {
};
Client.prototype.input = function(data) {
var client = this;
const client = this;
data.text.split("\n").forEach((line) => {
data.text = line;
client.inputLine(data);
@ -342,9 +338,8 @@ Client.prototype.input = function(data) {
};
Client.prototype.inputLine = function(data) {
var client = this;
var text = data.text;
var target = client.find(data.target);
const client = this;
const target = client.find(data.target);
if (!target) {
return;
}
@ -353,6 +348,8 @@ Client.prototype.inputLine = function(data) {
// so that reloading the page will open this channel
this.lastActiveChannel = target.chan.id;
let text = data.text;
// This is either a normal message or a command escaped with a leading '/'
if (text.charAt(0) !== "/" || text.charAt(1) === "/") {
if (target.chan.type === Chan.Type.LOBBY) {
@ -368,14 +365,14 @@ Client.prototype.inputLine = function(data) {
text = text.substr(1);
}
var args = text.split(" ");
var cmd = args.shift().toLowerCase();
const args = text.split(" ");
const cmd = args.shift().toLowerCase();
var irc = target.network.irc;
var connected = irc && irc.connection && irc.connection.connected;
const irc = target.network.irc;
let connected = irc && irc.connection && irc.connection.connected;
if (cmd in inputs) {
var plugin = inputs[cmd];
const plugin = inputs[cmd];
if (connected || plugin.allowDisconnected) {
connected = true;
plugin.input.apply(client, [target.network, target.chan, cmd, args]);
@ -460,8 +457,8 @@ Client.prototype.sort = function(data) {
break;
case "channels":
var network = _.find(this.networks, {id: data.target});
case "channels": {
const network = _.find(this.networks, {id: data.target});
if (!network) {
return;
}
@ -473,13 +470,14 @@ Client.prototype.sort = function(data) {
break;
}
}
this.save();
};
Client.prototype.names = function(data) {
var client = this;
var target = client.find(data.target);
const client = this;
const target = client.find(data.target);
if (!target) {
return;
}
@ -518,8 +516,8 @@ Client.prototype.quit = function(signOut) {
};
Client.prototype.clientAttach = function(socketId, token) {
var client = this;
var save = false;
const client = this;
let save = false;
if (client.awayMessage && _.size(client.attachedClients) === 0) {
client.networks.forEach(function(network) {
@ -544,7 +542,7 @@ Client.prototype.clientAttach = function(socketId, token) {
}
if (!network.hostname) {
var hostmask = (client.config && client.config.hostname) || client.hostname;
const hostmask = (client.config && client.config.hostname) || client.hostname;
if (hostmask) {
save = true;

View File

@ -17,7 +17,7 @@ program
return;
}
var child_spawn = child.spawn(
const child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Helper.getConfigPath()],
{stdio: "inherit"}

View File

@ -56,7 +56,7 @@ program
});
function add(manager, name, password, enableLog) {
var hash = Helper.password.hash(password);
const hash = Helper.password.hash(password);
manager.addUser(name, hash, enableLog);
log.info(`User ${colors.bold(name)} created.`);

View File

@ -28,7 +28,7 @@ program
log.error(`User ${colors.bold(name)} does not exist.`);
return;
}
var child_spawn = child.spawn(
const child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Helper.getUserConfigPath(name)],
{stdio: "inherit"}

View File

@ -27,8 +27,8 @@ program
log.error(`User ${colors.bold(name)} does not exist.`);
return;
}
var file = Helper.getUserConfigPath(name);
var user = require(file);
const file = Helper.getUserConfigPath(name);
const user = require(file);
log.prompt({
text: "Enter new password:",
silent: true,

View File

@ -1,12 +1,12 @@
"use strict";
const pkg = require("../package.json");
var _ = require("lodash");
var path = require("path");
var os = require("os");
var fs = require("fs");
var net = require("net");
var bcrypt = require("bcryptjs");
const _ = require("lodash");
const path = require("path");
const os = require("os");
const fs = require("fs");
const net = require("net");
const bcrypt = require("bcryptjs");
const colors = require("colors/safe");
let homePath;
@ -140,7 +140,7 @@ function ip2hex(address) {
}
return address.split(".").map(function(octet) {
var hex = parseInt(octet, 10).toString(16);
let hex = parseInt(octet, 10).toString(16);
if (hex.length === 1) {
hex = "0" + hex;

View File

@ -22,12 +22,12 @@ class Identification {
log.warn("Using both identd and oidentd at the same time, this is most likely not intended.");
}
var server = net.createServer(this.serverConnection.bind(this));
const server = net.createServer(this.serverConnection.bind(this));
server.listen({
port: Helper.config.identd.port || 113,
host: Helper.config.bind || Helper.config.host,
}, () => {
var address = server.address();
const address = server.address();
log.info(`Identd server available on ${colors.green(address.address + ":" + address.port)}`);
startedCallback(this);
@ -54,7 +54,7 @@ class Identification {
return;
}
for (var connection of this.connections.values()) {
for (const connection of this.connections.values()) {
if (connection.socket.remoteAddress === socket.remoteAddress
&& connection.socket.remotePort === fport
&& connection.socket.localPort === lport

View File

@ -1,9 +1,9 @@
"use strict";
var colors = require("colors/safe");
var moment = require("moment");
const colors = require("colors/safe");
const moment = require("moment");
const read = require("read");
var Helper = require("./helper");
const Helper = require("./helper");
function timestamp() {
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";

View File

@ -1,7 +1,7 @@
"use strict";
var _ = require("lodash");
var Helper = require("../helper");
const _ = require("lodash");
const Helper = require("../helper");
const User = require("./user");
const userLog = require("../userLog");
const storage = require("../plugins/storage");
@ -43,7 +43,7 @@ Chan.prototype.destroy = function() {
};
Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
var obj = {
const obj = {
chan: this.id,
msg: msg,
};
@ -110,7 +110,7 @@ Chan.prototype.getSortedUsers = function(irc) {
return users;
}
var userModeSortPriority = {};
const userModeSortPriority = {};
irc.network.options.PREFIX.forEach((prefix, index) => {
userModeSortPriority[prefix.symbol] = index;
});

View File

@ -1,8 +1,8 @@
"use strict";
var _ = require("lodash");
const _ = require("lodash");
var id = 0;
let id = 0;
class Msg {
constructor(attr) {

View File

@ -1,7 +1,7 @@
"use strict";
var _ = require("lodash");
var Chan = require("./chan");
const _ = require("lodash");
const Chan = require("./chan");
module.exports = Network;
@ -120,7 +120,7 @@ Network.prototype.getNetworkStatus = function() {
};
Network.prototype.export = function() {
var network = _.pick(this, [
const network = _.pick(this, [
"awayMessage",
"nick",
"name",

View File

@ -1,6 +1,6 @@
"use strict";
var _ = require("lodash");
const _ = require("lodash");
module.exports = User;

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["slap", "me"];
@ -15,7 +15,7 @@ exports.input = function({irc}, chan, cmd, args) {
return;
}
var text;
let text;
switch (cmd) {
case "slap":

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = [
"ban",

View File

@ -1,6 +1,6 @@
"use strict";
var Msg = require("../../models/msg");
const Msg = require("../../models/msg");
exports.commands = ["connect", "server"];
exports.allowDisconnected = true;
@ -24,8 +24,8 @@ exports.input = function({irc}, chan, cmd, args) {
return;
}
var port = args[1] || "";
var tls = port[0] === "+";
let port = args[1] || "";
const tls = port[0] === "+";
if (tls) {
port = port.substring(1);

View File

@ -5,7 +5,7 @@ const Helper = require("../../helper");
exports.commands = ["disconnect"];
exports.input = function({irc}, chan, cmd, args) {
var quitMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage;
const quitMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage;
irc.quit(quitMessage);
};

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["invite"];

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["kick"];

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = [
"mode",

View File

@ -3,26 +3,25 @@
exports.commands = ["msg", "say"];
exports.input = function(network, chan, cmd, args) {
var irc = network.irc;
var target = cmd === "msg" ? args.shift() : chan.name;
const target = cmd === "msg" ? args.shift() : chan.name;
if (args.length === 0 || !target) {
return true;
}
var msg = args.join(" ");
const msg = args.join(" ");
if (msg.length === 0) {
return true;
}
irc.say(target, msg);
network.irc.say(target, msg);
if (!network.irc.network.cap.isEnabled("echo-message")) {
var channel = network.getChannel(target);
const channel = network.getChannel(target);
if (typeof channel !== "undefined") {
irc.emit("privmsg", {
nick: irc.user.nick,
network.irc.emit("privmsg", {
nick: network.irc.user.nick,
target: channel.name,
message: msg,
});

View File

@ -1,6 +1,6 @@
"use strict";
var Msg = require("../../models/msg");
const Msg = require("../../models/msg");
exports.commands = ["nick"];
exports.allowDisconnected = true;
@ -22,7 +22,7 @@ exports.input = function(network, chan, cmd, args) {
return;
}
var newNick = args[0];
const newNick = args[0];
// If connected to IRC, send to server and wait for ACK
// otherwise update the nick and UI straight away

View File

@ -7,19 +7,19 @@ exports.input = function(network, chan, cmd, args) {
return;
}
var message = args.slice(1).join(" ");
var irc = network.irc;
irc.notice(args[0], message);
let targetChan = network.getChannel(args[0]);
let message = args.slice(1).join(" ");
network.irc.notice(args[0], message);
var targetChan = network.getChannel(args[0]);
if (typeof targetChan === "undefined") {
message = "{to " + args[0] + "} " + message;
targetChan = chan;
}
if (!network.irc.network.cap.isEnabled("echo-message")) {
irc.emit("notice", {
nick: irc.user.nick,
network.irc.emit("notice", {
nick: network.irc.user.nick,
target: targetChan.name,
message: message,
});

View File

@ -1,8 +1,8 @@
"use strict";
var _ = require("lodash");
var Msg = require("../../models/msg");
var Chan = require("../../models/chan");
const _ = require("lodash");
const Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Helper = require("../../helper");
exports.commands = ["close", "leave", "part"];

View File

@ -1,13 +1,13 @@
"use strict";
var _ = require("lodash");
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const _ = require("lodash");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["query"];
exports.input = function(network, chan, cmd, args) {
var target = args[0];
const target = args[0];
if (args.length === 0 || target.length === 0) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -16,12 +16,12 @@ exports.input = function(network, chan, cmd, args) {
return;
}
var query = _.find(network.channels, {name: target});
const query = _.find(network.channels, {name: target});
if (typeof query !== "undefined") {
return;
}
var char = target[0];
const char = target[0];
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.includes(char)) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -30,7 +30,7 @@ exports.input = function(network, chan, cmd, args) {
return;
}
for (var i = 0; i < network.irc.network.options.PREFIX.length; i++) {
for (let i = 0; i < network.irc.network.options.PREFIX.length; i++) {
if (network.irc.network.options.PREFIX[i].symbol === char) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -40,7 +40,7 @@ exports.input = function(network, chan, cmd, args) {
}
}
var newChan = new Chan({
const newChan = new Chan({
type: Chan.Type.QUERY,
name: target,
});

View File

@ -1,13 +1,13 @@
"use strict";
var _ = require("lodash");
const _ = require("lodash");
const Helper = require("../../helper");
exports.commands = ["quit"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) {
var client = this;
const client = this;
client.networks = _.without(client.networks, network);
network.destroy();

View File

@ -1,7 +1,7 @@
"use strict";
var Msg = require("../../models/msg");
var Chan = require("../../models/chan");
const Msg = require("../../models/msg");
const Chan = require("../../models/chan");
exports.commands = ["cycle", "rejoin"];

View File

@ -1,7 +1,7 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["topic"];

View File

@ -50,8 +50,8 @@ module.exports = function(client, chan, msg) {
function parse(msg, preview, res, client) {
switch (res.type) {
case "text/html":
var $ = cheerio.load(res.data);
case "text/html": {
const $ = cheerio.load(res.data);
preview.type = "link";
preview.head =
$('meta[property="og:title"]').attr("content")
@ -92,6 +92,7 @@ function parse(msg, preview, res, client) {
}
break;
}
case "image/png":
case "image/gif":

View File

@ -1,16 +1,16 @@
"use strict";
var _ = require("lodash");
var pkg = require("../package.json");
var Client = require("./client");
var ClientManager = require("./clientManager");
var express = require("express");
var fs = require("fs");
var path = require("path");
var io = require("socket.io");
var dns = require("dns");
var Helper = require("./helper");
var colors = require("colors/safe");
const _ = require("lodash");
const pkg = require("../package.json");
const Client = require("./client");
const ClientManager = require("./clientManager");
const express = require("express");
const fs = require("fs");
const path = require("path");
const io = require("socket.io");
const dns = require("dns");
const Helper = require("./helper");
const colors = require("colors/safe");
const net = require("net");
const Identification = require("./identification");
const changelog = require("./plugins/changelog");
@ -31,14 +31,14 @@ const authPlugins = [
// A random number that will force clients to reload the page if it differs
const serverHash = Math.floor(Date.now() * Math.random());
var manager = null;
let manager = null;
module.exports = function() {
log.info(`The Lounge ${colors.green(Helper.getVersion())} \
(Node.js ${colors.green(process.versions.node)} on ${colors.green(process.platform)} ${process.arch})`);
log.info(`Configuration file: ${colors.green(Helper.getConfigPath())}`);
var app = express()
const app = express()
.disable("x-powered-by")
.use(allRequests)
.use(index)
@ -72,20 +72,19 @@ module.exports = function() {
return res.sendFile(path.join(packagePath, fileName));
});
var config = Helper.config;
var server = null;
let server = null;
if (config.public && (config.ldap || {}).enable) {
if (Helper.config.public && (Helper.config.ldap || {}).enable) {
log.warn("Server is public and set to use LDAP. Set to private mode if trying to use LDAP authentication.");
}
if (!config.https.enable) {
if (!Helper.config.https.enable) {
server = require("http");
server = server.createServer(app);
} else {
const keyPath = Helper.expandHome(config.https.key);
const certPath = Helper.expandHome(config.https.certificate);
const caPath = Helper.expandHome(config.https.ca);
const keyPath = Helper.expandHome(Helper.config.https.key);
const certPath = Helper.expandHome(Helper.config.https.certificate);
const caPath = Helper.expandHome(Helper.config.https.ca);
if (!keyPath.length || !fs.existsSync(keyPath)) {
log.error("Path to SSL key is invalid. Stopping server...");
@ -112,12 +111,12 @@ module.exports = function() {
let listenParams;
if (typeof config.host === "string" && config.host.startsWith("unix:")) {
listenParams = config.host.replace(/^unix:/, "");
if (typeof Helper.config.host === "string" && Helper.config.host.startsWith("unix:")) {
listenParams = Helper.config.host.replace(/^unix:/, "");
} else {
listenParams = {
port: config.port,
host: config.host,
port: Helper.config.port,
host: Helper.config.host,
};
}
@ -127,23 +126,23 @@ module.exports = function() {
if (typeof listenParams === "string") {
log.info("Available on socket " + colors.green(listenParams));
} else {
const protocol = config.https.enable ? "https" : "http";
const protocol = Helper.config.https.enable ? "https" : "http";
const address = server.address();
log.info(
"Available at " +
colors.green(`${protocol}://${address.address}:${address.port}/`) +
` in ${colors.bold(config.public ? "public" : "private")} mode`
` in ${colors.bold(Helper.config.public ? "public" : "private")} mode`
);
}
const sockets = io(server, {
serveClient: false,
transports: config.transports,
transports: Helper.config.transports,
});
sockets.on("connect", (socket) => {
if (config.public) {
if (Helper.config.public) {
performAuthentication.call(socket, {});
} else {
socket.emit("auth", {
@ -302,9 +301,9 @@ function initializeClient(socket, client, token, lastMessage) {
socket.on(
"change-password",
function(data) {
var old = data.old_password;
var p1 = data.new_password;
var p2 = data.verify_password;
const old = data.old_password;
const p1 = data.new_password;
const p2 = data.verify_password;
if (typeof p1 === "undefined" || p1 === "") {
socket.emit("change-password", {
error: "Please enter a new password",

View File

@ -1,9 +1,9 @@
"use strict";
var fs = require("fs");
var fsextra = require("fs-extra");
var moment = require("moment");
var Helper = require("./helper");
const fs = require("fs");
const fsextra = require("fs-extra");
const moment = require("moment");
const Helper = require("./helper");
module.exports.write = function(user, network, chan, msg) {
const path = Helper.getUserLogsPath(user, network);
@ -15,13 +15,13 @@ module.exports.write = function(user, network, chan, msg) {
return;
}
var format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
var tz = Helper.config.logs.timezone || "UTC+00:00";
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
const tz = Helper.config.logs.timezone || "UTC+00:00";
var time = moment(msg.time).utcOffset(tz).format(format);
var line = `[${time}] `;
const time = moment(msg.time).utcOffset(tz).format(format);
let line = `[${time}] `;
var type = msg.type.trim();
const type = msg.type.trim();
if (type === "message" || type === "highlight") {
// Format:
// [2014-01-01 00:00:00] <Arnold> Put that cookie down.. Now!!

View File

@ -1,9 +1,9 @@
"use strict";
var expect = require("chai").expect;
const expect = require("chai").expect;
var Chan = require("../../src/models/chan");
var ModeCommand = require("../../src/plugins/inputs/mode");
const Chan = require("../../src/models/chan");
const ModeCommand = require("../../src/plugins/inputs/mode");
describe("Commands", function() {
describe("/mode", function() {

View File

@ -2,5 +2,5 @@
global.log = require("../../src/log.js");
var home = require("path").join(__dirname, ".lounge");
const home = require("path").join(__dirname, ".lounge");
require("../../src/helper").setHome(home);

View File

@ -82,7 +82,7 @@ describe("Chan", function() {
});
describe("#getSortedUsers(irc)", function() {
var getUserNames = function(chan) {
const getUserNames = function(chan) {
return chan.getSortedUsers(network).map((u) => u.nick);
};

View File

@ -9,7 +9,7 @@ const Network = require("../../src/models/network");
describe("Network", function() {
describe("#export()", function() {
it("should produce an valid object", function() {
var network = new Network({
const network = new Network({
awayMessage: "I am away",
name: "networkName",
channels: [
@ -47,7 +47,7 @@ describe("Network", function() {
});
it("lobby should be at the top", function() {
var network = new Network({
const network = new Network({
name: "Super Nice Network",
channels: [
new Chan({name: "AAAA!", type: Chan.Type.QUERY}),
@ -62,7 +62,7 @@ describe("Network", function() {
});
it("should maintain channel reference", function() {
var chan = new Chan({
const chan = new Chan({
name: "#506-bug-fix",
messages: [
new Msg({
@ -71,7 +71,7 @@ describe("Network", function() {
],
});
var network = new Network({
const network = new Network({
name: "networkName",
channels: [
chan,

View File

@ -1,10 +1,10 @@
"use strict";
var expect = require("chai").expect;
const expect = require("chai").expect;
var Network = require("../../src/models/network");
const Network = require("../../src/models/network");
var network = new Network({name: "networkName"});
const network = new Network({name: "networkName"});
describe("Nickname highlights", function() {
it("should NOT highlight nickname", function() {

View File

@ -1,11 +1,11 @@
"use strict";
var EventEmitter = require("events").EventEmitter;
var util = require("util");
var _ = require("lodash");
var express = require("express");
var Network = require("../src/models/network");
var Chan = require("../src/models/chan");
const EventEmitter = require("events").EventEmitter;
const util = require("util");
const _ = require("lodash");
const express = require("express");
const Network = require("../src/models/network");
const Chan = require("../src/models/chan");
function MockClient() {
this.user = {nick: "test-user"};
@ -13,7 +13,7 @@ function MockClient() {
util.inherits(MockClient, EventEmitter);
MockClient.prototype.createMessage = function(opts) {
var message = _.extend({
const message = _.extend({
text: "dummy message",
nick: "test-user",
target: "#test-channel",