mirror of
https://github.com/thelounge/thelounge
synced 2024-11-25 13:30:21 +00:00
Use forEach instead of lodash's each, and ES6 fat arrows like it's 2015
This commit is contained in:
parent
3711aefc2d
commit
089c315a8e
11 changed files with 26 additions and 42 deletions
|
@ -54,9 +54,7 @@ var inputs = [
|
||||||
].reduce(function(plugins, name) {
|
].reduce(function(plugins, name) {
|
||||||
var path = "./plugins/inputs/" + name;
|
var path = "./plugins/inputs/" + name;
|
||||||
var plugin = require(path);
|
var plugin = require(path);
|
||||||
plugin.commands.forEach(function(command) {
|
plugin.commands.forEach(command => plugins[command] = plugin);
|
||||||
plugins[command] = plugin;
|
|
||||||
});
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
@ -83,7 +81,7 @@ function Client(manager, name, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var delay = 0;
|
var delay = 0;
|
||||||
(client.config.networks || []).forEach(function(n) {
|
(client.config.networks || []).forEach(n => {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
client.connect(n);
|
client.connect(n);
|
||||||
}, delay);
|
}, delay);
|
||||||
|
@ -150,7 +148,7 @@ Client.prototype.connect = function(args) {
|
||||||
if (args.channels) {
|
if (args.channels) {
|
||||||
var badName = false;
|
var badName = false;
|
||||||
|
|
||||||
args.channels.forEach(function(chan) {
|
args.channels.forEach(chan => {
|
||||||
if (!chan.name) {
|
if (!chan.name) {
|
||||||
badName = true;
|
badName = true;
|
||||||
return;
|
return;
|
||||||
|
@ -248,7 +246,7 @@ Client.prototype.connect = function(args) {
|
||||||
"znc.in/self-message",
|
"znc.in/self-message",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
events.forEach(function(plugin) {
|
events.forEach(plugin => {
|
||||||
var path = "./plugins/irc-events/" + plugin;
|
var path = "./plugins/irc-events/" + plugin;
|
||||||
require(path).apply(client, [
|
require(path).apply(client, [
|
||||||
network.irc,
|
network.irc,
|
||||||
|
@ -311,7 +309,7 @@ Client.prototype.setPassword = function(hash, callback) {
|
||||||
|
|
||||||
Client.prototype.input = function(data) {
|
Client.prototype.input = function(data) {
|
||||||
var client = this;
|
var client = this;
|
||||||
data.text.split("\n").forEach(function(line) {
|
data.text.split("\n").forEach(line => {
|
||||||
data.text = line;
|
data.text = line;
|
||||||
client.inputLine(data);
|
client.inputLine(data);
|
||||||
});
|
});
|
||||||
|
@ -387,7 +385,7 @@ Client.prototype.sort = function(data) {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "networks":
|
case "networks":
|
||||||
_.each(order, function(i) {
|
order.forEach(i => {
|
||||||
var find = _.find(self.networks, {id: i});
|
var find = _.find(self.networks, {id: i});
|
||||||
if (find) {
|
if (find) {
|
||||||
sorted.push(find);
|
sorted.push(find);
|
||||||
|
@ -402,7 +400,7 @@ Client.prototype.sort = function(data) {
|
||||||
if (!network) {
|
if (!network) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_.each(order, function(i) {
|
order.forEach(i => {
|
||||||
var find = _.find(network.channels, {id: i});
|
var find = _.find(network.channels, {id: i});
|
||||||
if (find) {
|
if (find) {
|
||||||
sorted.push(find);
|
sorted.push(find);
|
||||||
|
@ -437,7 +435,7 @@ Client.prototype.quit = function() {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.networks.forEach(function(network) {
|
this.networks.forEach(network => {
|
||||||
if (network.irc) {
|
if (network.irc) {
|
||||||
network.irc.quit("Page closed");
|
network.irc.quit("Page closed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ ClientManager.prototype.getUsers = function() {
|
||||||
var users = [];
|
var users = [];
|
||||||
try {
|
try {
|
||||||
var files = fs.readdirSync(Helper.USERS_PATH);
|
var files = fs.readdirSync(Helper.USERS_PATH);
|
||||||
files.forEach(function(file) {
|
files.forEach(file => {
|
||||||
if (file.indexOf(".json") !== -1) {
|
if (file.indexOf(".json") !== -1) {
|
||||||
users.push(file.replace(".json", ""));
|
users.push(file.replace(".json", ""));
|
||||||
}
|
}
|
||||||
|
@ -148,11 +148,10 @@ ClientManager.prototype.autoload = function(/* sockets */) {
|
||||||
"name"
|
"name"
|
||||||
);
|
);
|
||||||
var added = _.difference(self.getUsers(), loaded);
|
var added = _.difference(self.getUsers(), loaded);
|
||||||
_.each(added, function(name) {
|
added.forEach(name => self.loadUser(name));
|
||||||
self.loadUser(name);
|
|
||||||
});
|
|
||||||
var removed = _.difference(loaded, self.getUsers());
|
var removed = _.difference(loaded, self.getUsers());
|
||||||
_.each(removed, function(name) {
|
removed.forEach(name => {
|
||||||
var client = _.find(
|
var client = _.find(
|
||||||
self.clients, {
|
self.clients, {
|
||||||
name: name
|
name: name
|
||||||
|
|
|
@ -59,7 +59,7 @@ Chan.prototype.pushMessage = function(client, msg) {
|
||||||
|
|
||||||
Chan.prototype.sortUsers = function(irc) {
|
Chan.prototype.sortUsers = function(irc) {
|
||||||
var userModeSortPriority = {};
|
var userModeSortPriority = {};
|
||||||
irc.network.options.PREFIX.forEach(function(prefix, index) {
|
irc.network.options.PREFIX.forEach((prefix, index) => {
|
||||||
userModeSortPriority[prefix.symbol] = index;
|
userModeSortPriority[prefix.symbol] = index;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
|
||||||
var identd = require("../../identd");
|
var identd = require("../../identd");
|
||||||
var Msg = require("../../models/msg");
|
var Msg = require("../../models/msg");
|
||||||
var Chan = require("../../models/chan");
|
var Chan = require("../../models/chan");
|
||||||
|
@ -24,7 +23,7 @@ module.exports = function(irc, network) {
|
||||||
var delay = 1000;
|
var delay = 1000;
|
||||||
var commands = network.commands;
|
var commands = network.commands;
|
||||||
if (Array.isArray(commands)) {
|
if (Array.isArray(commands)) {
|
||||||
commands.forEach(function(cmd) {
|
commands.forEach(cmd => {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
client.input({
|
client.input({
|
||||||
target: network.channels[0].id,
|
target: network.channels[0].id,
|
||||||
|
@ -35,7 +34,7 @@ module.exports = function(irc, network) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
network.channels.forEach(function(chan) {
|
network.channels.forEach(chan => {
|
||||||
if (chan.type !== Chan.Type.CHANNEL) {
|
if (chan.type !== Chan.Type.CHANNEL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +113,7 @@ module.exports = function(irc, network) {
|
||||||
|
|
||||||
network.prefixLookup = {};
|
network.prefixLookup = {};
|
||||||
|
|
||||||
_.each(data.options.PREFIX, function(mode) {
|
data.options.PREFIX.forEach(mode => {
|
||||||
network.prefixLookup[mode.mode] = mode.symbol;
|
network.prefixLookup[mode.mode] = mode.symbol;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
|
||||||
var cheerio = require("cheerio");
|
var cheerio = require("cheerio");
|
||||||
var Msg = require("../../models/msg");
|
var Msg = require("../../models/msg");
|
||||||
var request = require("request");
|
var request = require("request");
|
||||||
|
@ -16,13 +15,10 @@ module.exports = function(irc, network) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var links = [];
|
const links = data.message
|
||||||
var split = data.message.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").split(" ");
|
.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "")
|
||||||
_.each(split, function(w) {
|
.split(" ")
|
||||||
if (/^https?:\/\//.test(w)) {
|
.filter(w => /^https?:\/\//.test(w));
|
||||||
links.push(w);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (links.length === 0) {
|
if (links.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = function(irc, network) {
|
||||||
var supportsMultiPrefix = network.irc.network.cap.isEnabled("multi-prefix");
|
var supportsMultiPrefix = network.irc.network.cap.isEnabled("multi-prefix");
|
||||||
var userModeSortPriority = {};
|
var userModeSortPriority = {};
|
||||||
|
|
||||||
irc.network.options.PREFIX.forEach(function(prefix, index) {
|
irc.network.options.PREFIX.forEach((prefix, index) => {
|
||||||
userModeSortPriority[prefix.symbol] = index;
|
userModeSortPriority[prefix.symbol] = index;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = function(irc, network) {
|
||||||
var lobby = network.channels[0];
|
var lobby = network.channels[0];
|
||||||
|
|
||||||
if (data.motd) {
|
if (data.motd) {
|
||||||
data.motd.split("\n").forEach(function(text) {
|
data.motd.split("\n").forEach(text => {
|
||||||
var msg = new Msg({
|
var msg = new Msg({
|
||||||
type: Msg.Type.MOTD,
|
type: Msg.Type.MOTD,
|
||||||
text: text
|
text: text
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
|
||||||
var User = require("../../models/user");
|
var User = require("../../models/user");
|
||||||
|
|
||||||
module.exports = function(irc, network) {
|
module.exports = function(irc, network) {
|
||||||
|
@ -11,13 +10,7 @@ module.exports = function(irc, network) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chan.users = [];
|
chan.users = data.users.map(u => new User(u, network.prefixLookup));
|
||||||
|
|
||||||
_.each(data.users, function(u) {
|
|
||||||
var user = new User(u, network.prefixLookup);
|
|
||||||
|
|
||||||
chan.users.push(user);
|
|
||||||
});
|
|
||||||
|
|
||||||
chan.sortUsers(irc);
|
chan.sortUsers(irc);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ module.exports = function(irc, network) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
network.channels.forEach(function(chan) {
|
network.channels.forEach(chan => {
|
||||||
var user = _.find(chan.users, {name: data.nick});
|
var user = _.find(chan.users, {name: data.nick});
|
||||||
if (typeof user === "undefined") {
|
if (typeof user === "undefined") {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,7 +6,7 @@ var Msg = require("../../models/msg");
|
||||||
module.exports = function(irc, network) {
|
module.exports = function(irc, network) {
|
||||||
var client = this;
|
var client = this;
|
||||||
irc.on("quit", function(data) {
|
irc.on("quit", function(data) {
|
||||||
network.channels.forEach(function(chan) {
|
network.channels.forEach(chan => {
|
||||||
var from = data.nick;
|
var from = data.nick;
|
||||||
var user = _.find(chan.users, {name: from});
|
var user = _.find(chan.users, {name: from});
|
||||||
if (typeof user === "undefined") {
|
if (typeof user === "undefined") {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
|
||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
|
|
||||||
var Chan = require("../../src/models/chan");
|
var Chan = require("../../src/models/chan");
|
||||||
|
@ -24,7 +23,7 @@ describe("Chan", function() {
|
||||||
|
|
||||||
var prefixLookup = {};
|
var prefixLookup = {};
|
||||||
|
|
||||||
_.each(network.network.options.PREFIX, function(mode) {
|
network.network.options.PREFIX.forEach(mode => {
|
||||||
prefixLookup[mode.mode] = mode.symbol;
|
prefixLookup[mode.mode] = mode.symbol;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue