From 560de1ac38a7afb8b25ebcaf3d444a05a74f015e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orvar=20Segerstr=C3=B6m?= Date: Sun, 19 Oct 2014 13:58:31 +0200 Subject: [PATCH] Send NOTICE messages to the correct channel Fixes #177 --- src/plugins/irc-events/notice.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugins/irc-events/notice.js b/src/plugins/irc-events/notice.js index d5400fa2..0f8c057f 100644 --- a/src/plugins/irc-events/notice.js +++ b/src/plugins/irc-events/notice.js @@ -1,9 +1,19 @@ +var _ = require("lodash"); var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("notice", function(data) { - var lobby = network.channels[0]; + var target = data.to; + if (target.toLowerCase() == irc.me.toLowerCase()) { + target = data.from; + } + + var chan = _.findWhere(network.channels, {name: target}); + if (typeof chan === "undefined") { + chan = network.channels[0]; + } + var from = data.from || ""; if (data.to == "*" || data.from.indexOf(".") !== -1) { from = ""; @@ -13,9 +23,9 @@ module.exports = function(irc, network) { from: from, text: data.message }); - lobby.messages.push(msg); + chan.messages.push(msg); client.emit("msg", { - chan: lobby.id, + chan: chan.id, msg: msg }); });