Use findUser

This commit is contained in:
Pavel Djundik 2017-07-11 17:30:47 +03:00
parent d06c279f02
commit 48d367e379
5 changed files with 9 additions and 9 deletions

View File

@ -11,10 +11,12 @@ module.exports = function(irc, network) {
return; return;
} }
const user = chan.findUser(data.kicked);
if (data.kicked === irc.user.nick) { if (data.kicked === irc.user.nick) {
chan.users = []; chan.users = [];
} else { } else {
chan.users = _.without(chan.users, _.find(chan.users, {nick: data.kicked})); chan.users = _.without(chan.users, user);
} }
client.emit("users", { client.emit("users", {
@ -24,7 +26,7 @@ module.exports = function(irc, network) {
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.KICK, type: Msg.Type.KICK,
time: data.time, time: data.time,
mode: chan.getMode(data.nick), mode: user.mode,
from: data.nick, from: data.nick,
target: data.kicked, target: data.kicked,
text: data.message || "", text: data.message || "",

View File

@ -81,7 +81,7 @@ module.exports = function(irc, network) {
return; return;
} }
const user = _.find(targetChan.users, {nick: mode.param}); const user = targetChan.findUser(mode.param);
if (!user) { if (!user) {
return; return;
} }

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
@ -25,7 +24,7 @@ module.exports = function(irc, network) {
} }
network.channels.forEach((chan) => { network.channels.forEach((chan) => {
var user = _.find(chan.users, {nick: data.nick}); const user = chan.findUser(data.nick);
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }

View File

@ -18,7 +18,7 @@ module.exports = function(irc, network) {
chan: chan.id chan: chan.id
}); });
} else { } else {
var user = _.find(chan.users, {nick: from}); const user = chan.findUser(from);
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
client.emit("users", { client.emit("users", {
chan: chan.id chan: chan.id

View File

@ -7,8 +7,7 @@ module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("quit", function(data) { irc.on("quit", function(data) {
network.channels.forEach((chan) => { network.channels.forEach((chan) => {
var from = data.nick; const user = chan.findUser(data.nick);
var user = _.find(chan.users, {nick: from});
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }
@ -22,7 +21,7 @@ module.exports = function(irc, network) {
mode: user.mode || "", mode: user.mode || "",
text: data.message || "", text: data.message || "",
hostmask: data.ident + "@" + data.hostname, hostmask: data.ident + "@" + data.hostname,
from: from from: data.nick
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);
}); });