From 360563528a5b526ca8d728074d3cf0fd63290f73 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 8 Mar 2016 11:42:38 +0200 Subject: [PATCH] Handle channel and user modes --- src/plugins/irc-events/mode.js | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/plugins/irc-events/mode.js b/src/plugins/irc-events/mode.js index f6ca2a21..d50117a7 100644 --- a/src/plugins/irc-events/mode.js +++ b/src/plugins/irc-events/mode.js @@ -1,28 +1,38 @@ var _ = require("lodash"); +var Chan = require("../../models/chan"); var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("mode", function(data) { - var chan = _.find(network.channels, {name: data.target}); - if (typeof chan !== "undefined") { - setTimeout(function() { - irc.write("NAMES " + data.target); - }, 200); - var from = data.nick; - if (from.indexOf(".") !== -1) { - from = data.target; + var targetChan; + + if (data.target === irc.user.nick) { + targetChan = network.channels[0]; + } else { + targetChan = _.find(network.channels, {name: data.target}); + if (typeof targetChan === "undefined") { + return; } + } + + for (var i = 0; i < data.modes.length; i++) { + var mode = data.modes[i]; + var text = mode.mode; + if (mode.param) { + text += " " + mode.param; + } + var msg = new Msg({ type: Msg.Type.MODE, - mode: chan.getMode(from), - from: from, - text: data.mode + " " + (data.client || ""), - self: from === irc.user.nick + mode: (targetChan.type !== Chan.Type.LOBBY && targetChan.getMode(data.nick)) || "", + from: data.nick, + text: text, + self: data.nick === irc.user.nick }); - chan.messages.push(msg); + targetChan.messages.push(msg); client.emit("msg", { - chan: chan.id, + chan: targetChan.id, msg: msg, }); }