mirror of
https://github.com/thelounge/thelounge
synced 2024-11-21 19:43:07 +00:00
Use some ES6/Node v4-only syntax when possible
This commit is contained in:
parent
6013a02fc2
commit
416f45d1e3
27 changed files with 70 additions and 87 deletions
|
@ -89,9 +89,9 @@ function onPushButton() {
|
|||
userVisibleOnly: true,
|
||||
}).then((subscription) => {
|
||||
const rawKey = subscription.getKey ? subscription.getKey("p256dh") : "";
|
||||
const key = rawKey ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(rawKey))) : "";
|
||||
const key = rawKey ? window.btoa(String.fromCharCode(...new Uint8Array(rawKey))) : "";
|
||||
const rawAuthSecret = subscription.getKey ? subscription.getKey("auth") : "";
|
||||
const authSecret = rawAuthSecret ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(rawAuthSecret))) : "";
|
||||
const authSecret = rawAuthSecret ? window.btoa(String.fromCharCode(...new Uint8Array(rawAuthSecret))) : "";
|
||||
|
||||
socket.emit("push:register", {
|
||||
token: storage.get("token"),
|
||||
|
|
|
@ -16,7 +16,7 @@ request.get({
|
|||
const shortname = prepareShortName(emojiStrategy[key].shortname);
|
||||
|
||||
// Skip tones, at least for now
|
||||
if (shortname.indexOf("tone") > -1) {
|
||||
if (shortname.includes("tone")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,11 +65,7 @@ var inputs = [
|
|||
return plugins;
|
||||
}, {});
|
||||
|
||||
function Client(manager, name, config) {
|
||||
if (typeof config !== "object") {
|
||||
config = {};
|
||||
}
|
||||
|
||||
function Client(manager, name, config = {}) {
|
||||
_.merge(this, {
|
||||
awayMessage: config.awayMessage || "",
|
||||
lastActiveChannel: -1,
|
||||
|
|
|
@ -24,7 +24,7 @@ program
|
|||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) !== -1) {
|
||||
if (users.includes(name)) {
|
||||
log.error(`User ${colors.bold(name)} already exists.`);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ program
|
|||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) === -1) {
|
||||
if (!users.includes(name)) {
|
||||
log.error(`User ${colors.bold(name)} does not exist.`);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ program
|
|||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) === -1) {
|
||||
if (!users.includes(name)) {
|
||||
log.error(`User ${colors.bold(name)} does not exist.`);
|
||||
return;
|
||||
}
|
||||
|
|
35
src/log.js
35
src/log.js
|
@ -5,41 +5,38 @@ var moment = require("moment");
|
|||
const read = require("read");
|
||||
var Helper = require("./helper");
|
||||
|
||||
function timestamp(type, messageArgs) {
|
||||
var format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
|
||||
var tz = Helper.config.logs.timezone || "UTC+00:00";
|
||||
function timestamp() {
|
||||
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
|
||||
const tz = Helper.config.logs.timezone || "UTC+00:00";
|
||||
const time = moment().utcOffset(tz).format(format);
|
||||
|
||||
var time = moment().utcOffset(tz).format(format);
|
||||
|
||||
Array.prototype.unshift.call(messageArgs, colors.dim(time), type);
|
||||
|
||||
return messageArgs;
|
||||
return colors.dim(time);
|
||||
}
|
||||
|
||||
/* eslint-disable no-console */
|
||||
exports.error = function() {
|
||||
console.error.apply(console, timestamp(colors.red("[ERROR]"), arguments));
|
||||
exports.error = function(...args) {
|
||||
console.error(timestamp(), colors.red("[ERROR]"), ...args);
|
||||
};
|
||||
|
||||
exports.warn = function() {
|
||||
console.error.apply(console, timestamp(colors.yellow("[WARN]"), arguments));
|
||||
exports.warn = function(...args) {
|
||||
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
|
||||
};
|
||||
|
||||
exports.info = function() {
|
||||
console.log.apply(console, timestamp(colors.blue("[INFO]"), arguments));
|
||||
exports.info = function(...args) {
|
||||
console.log(timestamp(), colors.blue("[INFO]"), ...args);
|
||||
};
|
||||
|
||||
exports.debug = function() {
|
||||
console.log.apply(console, timestamp(colors.green("[DEBUG]"), arguments));
|
||||
exports.debug = function(...args) {
|
||||
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
|
||||
};
|
||||
|
||||
exports.raw = function() {
|
||||
console.log.apply(console, arguments);
|
||||
exports.raw = function(...args) {
|
||||
console.log(...args);
|
||||
};
|
||||
|
||||
/* eslint-enable no-console */
|
||||
|
||||
exports.prompt = (options, callback) => {
|
||||
options.prompt = timestamp(colors.cyan("[PROMPT]"), [options.text]).join(" ");
|
||||
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
|
||||
read(options, callback);
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
|
|||
|
||||
exports.commands = ["slap", "me"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (chan.type !== Chan.Type.CHANNEL && chan.type !== Chan.Type.QUERY) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
|
@ -15,7 +15,6 @@ exports.input = function(network, chan, cmd, args) {
|
|||
return;
|
||||
}
|
||||
|
||||
var irc = network.irc;
|
||||
var text;
|
||||
|
||||
switch (cmd) {
|
||||
|
@ -31,7 +30,7 @@ exports.input = function(network, chan, cmd, args) {
|
|||
|
||||
irc.action(chan.name, text);
|
||||
|
||||
if (!network.irc.network.cap.isEnabled("echo-message")) {
|
||||
if (!irc.network.cap.isEnabled("echo-message")) {
|
||||
irc.emit("action", {
|
||||
nick: irc.user.nick,
|
||||
target: chan.name,
|
||||
|
|
|
@ -9,7 +9,7 @@ exports.commands = [
|
|||
"banlist",
|
||||
];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (chan.type !== Chan.Type.CHANNEL) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
|
@ -32,13 +32,13 @@ exports.input = function(network, chan, cmd, args) {
|
|||
|
||||
switch (cmd) {
|
||||
case "ban":
|
||||
network.irc.ban(chan.name, args[0]);
|
||||
irc.ban(chan.name, args[0]);
|
||||
break;
|
||||
case "unban":
|
||||
network.irc.unban(chan.name, args[0]);
|
||||
irc.unban(chan.name, args[0]);
|
||||
break;
|
||||
case "banlist":
|
||||
network.irc.banlist(chan.name);
|
||||
irc.banlist(chan.name);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,13 +5,13 @@ var Msg = require("../../models/msg");
|
|||
exports.commands = ["connect", "server"];
|
||||
exports.allowDisconnected = true;
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (args.length === 0) {
|
||||
if (!network.irc || !network.irc.connection) {
|
||||
if (!irc || !irc.connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (network.irc.connection.connected) {
|
||||
if (irc.connection.connected) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
text: "You are already connected.",
|
||||
|
@ -19,7 +19,7 @@ exports.input = function(network, chan, cmd, args) {
|
|||
return;
|
||||
}
|
||||
|
||||
network.irc.connection.connect();
|
||||
irc.connection.connect();
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
exports.commands = ["ctcp"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (args.length > 1) {
|
||||
var irc = network.irc;
|
||||
irc.ctcpRequest(args[0], args.slice(1).join(" "));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,8 +4,8 @@ const Helper = require("../../helper");
|
|||
|
||||
exports.commands = ["disconnect"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
var quitMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage;
|
||||
|
||||
network.irc.quit(quitMessage);
|
||||
irc.quit(quitMessage);
|
||||
};
|
||||
|
|
|
@ -5,9 +5,7 @@ var Msg = require("../../models/msg");
|
|||
|
||||
exports.commands = ["invite"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var irc = network.irc;
|
||||
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (args.length === 2) {
|
||||
irc.raw("INVITE", args[0], args[1]); // Channel provided in the command
|
||||
} else if (args.length === 1 && chan.type === Chan.Type.CHANNEL) {
|
||||
|
|
|
@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
|
|||
|
||||
exports.commands = ["kick"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (chan.type !== Chan.Type.CHANNEL) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
|
@ -16,7 +16,6 @@ exports.input = function(network, chan, cmd, args) {
|
|||
}
|
||||
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.raw("KICK", chan.name, args[0], args.slice(1).join(" "));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,6 @@ exports.commands = ["list"];
|
|||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
network.chanCache = [];
|
||||
network.irc.list.apply(network.irc, args);
|
||||
network.irc.list(...args);
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ exports.commands = [
|
|||
"devoice",
|
||||
];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc, nick}, chan, cmd, args) {
|
||||
if (cmd !== "mode") {
|
||||
if (chan.type !== Chan.Type.CHANNEL) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
|
@ -43,17 +43,15 @@ exports.input = function(network, chan, cmd, args) {
|
|||
}[cmd];
|
||||
|
||||
args.forEach(function(target) {
|
||||
network.irc.raw("MODE", chan.name, mode, target);
|
||||
irc.raw("MODE", chan.name, mode, target);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length === 0 || args[0][0] === "+" || args[0][0] === "-") {
|
||||
args.unshift(chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : network.nick);
|
||||
args.unshift(chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : nick);
|
||||
}
|
||||
|
||||
args.unshift("MODE");
|
||||
|
||||
network.irc.raw.apply(network.irc, args);
|
||||
irc.raw("MODE", ...args);
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ exports.input = function(network, chan, cmd, args) {
|
|||
}
|
||||
|
||||
var char = target[0];
|
||||
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.indexOf(char) !== -1) {
|
||||
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.includes(char)) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
text: "You can not open query windows for channels, use /join instead.",
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
exports.commands = ["raw", "send", "quote"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (args.length !== 0) {
|
||||
var irc = network.irc;
|
||||
irc.raw(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ var Chan = require("../../models/chan");
|
|||
|
||||
exports.commands = ["cycle", "rejoin"];
|
||||
|
||||
exports.input = function(network, chan) {
|
||||
exports.input = function({irc}, chan) {
|
||||
if (chan.type !== Chan.Type.CHANNEL) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
|
@ -14,8 +14,8 @@ exports.input = function(network, chan) {
|
|||
return;
|
||||
}
|
||||
|
||||
network.irc.part(chan.name, "Rejoining");
|
||||
network.irc.join(chan.name);
|
||||
irc.part(chan.name, "Rejoining");
|
||||
irc.join(chan.name);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
|
|||
|
||||
exports.commands = ["topic"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (chan.type !== Chan.Type.CHANNEL) {
|
||||
chan.pushMessage(this, new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
|
@ -14,6 +14,6 @@ exports.input = function(network, chan, cmd, args) {
|
|||
|
||||
return;
|
||||
}
|
||||
network.irc.setTopic(chan.name, args.join(" "));
|
||||
irc.setTopic(chan.name, args.join(" "));
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
exports.commands = ["whois"];
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
exports.input = function({irc}, chan, cmd, args) {
|
||||
if (args.length === 1) {
|
||||
// This queries server of the other user and not of the current user, which
|
||||
// does not know idle time.
|
||||
// See http://superuser.com/a/272069/208074.
|
||||
network.irc.raw("WHOIS", args[0], args[0]);
|
||||
irc.raw("WHOIS", args[0], args[0]);
|
||||
} else {
|
||||
// Re-assembling the command parsed in client.js
|
||||
network.irc.raw(`${cmd} ${args.join(" ")}`);
|
||||
irc.raw(`${cmd} ${args.join(" ")}`);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -114,7 +114,7 @@ module.exports = function(irc, network) {
|
|||
}
|
||||
|
||||
// No prefetch URLs unless are simple MESSAGE or ACTION types
|
||||
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].indexOf(data.type) !== -1) {
|
||||
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].includes(data.type)) {
|
||||
LinkPrefetch(client, chan, msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ module.exports = function(irc, network) {
|
|||
|
||||
if (!add) {
|
||||
_.pull(user.modes, changedMode);
|
||||
} else if (user.modes.indexOf(changedMode) === -1) {
|
||||
} else if (!user.modes.includes(changedMode)) {
|
||||
user.modes.push(changedMode);
|
||||
user.modes.sort(function(a, b) {
|
||||
return userModeSortPriority[a] - userModeSortPriority[b];
|
||||
|
|
|
@ -38,13 +38,13 @@ class WebPush {
|
|||
}
|
||||
|
||||
push(client, payload, onlyToOffline) {
|
||||
_.forOwn(client.config.sessions, (session, token) => {
|
||||
if (session.pushSubscription) {
|
||||
if (onlyToOffline && _.find(client.attachedClients, {token: token}) !== undefined) {
|
||||
_.forOwn(client.config.sessions, ({pushSubscription}, token) => {
|
||||
if (pushSubscription) {
|
||||
if (onlyToOffline && _.find(client.attachedClients, {token}) !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pushSingle(client, session.pushSubscription, payload);
|
||||
this.pushSingle(client, pushSubscription, payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ class WebPush {
|
|||
if (error.statusCode >= 400 && error.statusCode < 500) {
|
||||
log.warn(`WebPush subscription for ${client.name} returned an error (${error.statusCode}), removing subscription`);
|
||||
|
||||
_.forOwn(client.config.sessions, (session, token) => {
|
||||
if (session.pushSubscription && session.pushSubscription.endpoint === subscription.endpoint) {
|
||||
_.forOwn(client.config.sessions, ({pushSubscription}, token) => {
|
||||
if (pushSubscription && pushSubscription.endpoint === subscription.endpoint) {
|
||||
client.unregisterPushSubscription(token);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,8 +20,8 @@ describe("Commands", function() {
|
|||
lastCommand: null,
|
||||
nick: "xPaw",
|
||||
irc: {
|
||||
raw: function() {
|
||||
testableNetwork.lastCommand = Array.prototype.join.call(arguments, " ");
|
||||
raw: function(...args) {
|
||||
testableNetwork.lastCommand = args.join(" ");
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
14
test/util.js
14
test/util.js
|
@ -24,14 +24,12 @@ MockClient.prototype.createMessage = function(opts) {
|
|||
};
|
||||
|
||||
function mockLogger(callback) {
|
||||
return function() {
|
||||
// TODO: Use ...args with The Lounge v3: add `...args` as function argument
|
||||
// and replaced the next line with `args.join(", ")`
|
||||
const stdout = Array.prototype.slice.call(arguments).join(" ")
|
||||
.replace( // Removes ANSI colors. See https://stackoverflow.com/a/29497680
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
||||
""
|
||||
);
|
||||
return function(...args) {
|
||||
// Concats and removes ANSI colors. See https://stackoverflow.com/a/29497680
|
||||
const stdout = args.join(" ").replace(
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
||||
""
|
||||
);
|
||||
|
||||
callback(stdout + "\n");
|
||||
};
|
||||
|
|
|
@ -101,7 +101,7 @@ const config = {
|
|||
// automatically split all vendor dependencies into a separate bundle
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: "js/bundle.vendor.js",
|
||||
minChunks: (module) => module.context && module.context.indexOf("node_modules") !== -1,
|
||||
minChunks: (module) => module.context && module.context.includes("node_modules"),
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue