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