From e0fb454223b22f65b1a112e1aba17b6711dd9bc1 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 20 Mar 2016 16:28:47 +0200 Subject: [PATCH] Search channel case insensitively --- src/models/network.js | 8 ++++++++ src/plugins/inputs/msg.js | 4 +--- src/plugins/inputs/notice.js | 4 +--- src/plugins/irc-events/invite.js | 3 +-- src/plugins/irc-events/join.js | 3 +-- src/plugins/irc-events/kick.js | 2 +- src/plugins/irc-events/link.js | 2 +- src/plugins/irc-events/message.js | 3 +-- src/plugins/irc-events/mode.js | 2 +- src/plugins/irc-events/names.js | 2 +- src/plugins/irc-events/part.js | 2 +- src/plugins/irc-events/topic.js | 5 ++--- src/plugins/irc-events/whois.js | 3 +-- 13 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/models/network.js b/src/models/network.js index cb6d4735..1df03704 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -55,6 +55,14 @@ Network.prototype.export = function() { return network; }; +Network.prototype.getChannel = function(name) { + name = name.toLowerCase(); + + return _.find(this.channels, function(that) { + return that.name.toLowerCase() === name; + }); +}; + function prettify(host) { var name = capitalize(host.split(".")[1]); if (!name) { diff --git a/src/plugins/inputs/msg.js b/src/plugins/inputs/msg.js index 1e98d886..a562b607 100644 --- a/src/plugins/inputs/msg.js +++ b/src/plugins/inputs/msg.js @@ -1,5 +1,3 @@ -var _ = require("lodash"); - exports.commands = ["msg", "say"]; exports.input = function(network, chan, cmd, args) { @@ -21,7 +19,7 @@ exports.input = function(network, chan, cmd, args) { var msg = args.join(" "); irc.say(target, msg); - var channel = _.find(network.channels, {name: target}); + var channel = network.getChannel(target); if (typeof channel !== "undefined") { irc.emit("privmsg", { nick: irc.user.nick, diff --git a/src/plugins/inputs/notice.js b/src/plugins/inputs/notice.js index e16cb74b..33aeda00 100644 --- a/src/plugins/inputs/notice.js +++ b/src/plugins/inputs/notice.js @@ -1,5 +1,3 @@ -var _ = require("lodash"); - exports.commands = ["notice"]; exports.input = function(network, chan, cmd, args) { @@ -11,7 +9,7 @@ exports.input = function(network, chan, cmd, args) { var irc = network.irc; irc.notice(args[0], message); - var targetChan = _.find(network.channels, {name: args[0]}); + var targetChan = network.getChannel(args[0]); if (typeof targetChan === "undefined") { message = "{to " + args[0] + "} " + message; targetChan = chan; diff --git a/src/plugins/irc-events/invite.js b/src/plugins/irc-events/invite.js index cc3a4229..0f00e87d 100644 --- a/src/plugins/irc-events/invite.js +++ b/src/plugins/irc-events/invite.js @@ -1,4 +1,3 @@ -var _ = require("lodash"); var Msg = require("../../models/msg"); module.exports = function(irc, network) { @@ -6,7 +5,7 @@ module.exports = function(irc, network) { irc.on("invite", function(data) { var target = data.to; - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { chan = network.channels[0]; } diff --git a/src/plugins/irc-events/join.js b/src/plugins/irc-events/join.js index e447f99e..d2f6496e 100644 --- a/src/plugins/irc-events/join.js +++ b/src/plugins/irc-events/join.js @@ -1,4 +1,3 @@ -var _ = require("lodash"); var Chan = require("../../models/chan"); var Msg = require("../../models/msg"); var User = require("../../models/user"); @@ -6,7 +5,7 @@ var User = require("../../models/user"); module.exports = function(irc, network) { var client = this; irc.on("join", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { chan = new Chan({ name: data.channel diff --git a/src/plugins/irc-events/kick.js b/src/plugins/irc-events/kick.js index d1713e19..8e2522d9 100644 --- a/src/plugins/irc-events/kick.js +++ b/src/plugins/irc-events/kick.js @@ -4,7 +4,7 @@ var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("kick", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { return; } diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 1f687b73..1f19bba0 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -27,7 +27,7 @@ module.exports = function(irc, network) { return; } - var chan = _.find(network.channels, {name: data.target}); + var chan = network.getChannel(data.target); if (typeof chan === "undefined") { return; } diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index f9338dee..42a7aa9d 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -1,4 +1,3 @@ -var _ = require("lodash"); var Chan = require("../../models/chan"); var Msg = require("../../models/msg"); var Helper = require("../../helper"); @@ -34,7 +33,7 @@ module.exports = function(irc, network) { target = data.nick; } - var chan = _.find(network.channels, {name: target}); + var chan = network.getChannel(target); if (typeof chan === "undefined") { chan = new Chan({ type: Chan.Type.QUERY, diff --git a/src/plugins/irc-events/mode.js b/src/plugins/irc-events/mode.js index e205c66c..1444720f 100644 --- a/src/plugins/irc-events/mode.js +++ b/src/plugins/irc-events/mode.js @@ -10,7 +10,7 @@ module.exports = function(irc, network) { if (data.target === irc.user.nick) { targetChan = network.channels[0]; } else { - targetChan = _.find(network.channels, {name: data.target}); + targetChan = network.getChannel(data.target); if (typeof targetChan === "undefined") { return; } diff --git a/src/plugins/irc-events/names.js b/src/plugins/irc-events/names.js index a41c7541..4307ff22 100644 --- a/src/plugins/irc-events/names.js +++ b/src/plugins/irc-events/names.js @@ -4,7 +4,7 @@ var User = require("../../models/user"); module.exports = function(irc, network) { var client = this; irc.on("userlist", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { return; } diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index 8043920a..5aee2c49 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -4,7 +4,7 @@ var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("part", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { return; } diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index 0330d139..be63c451 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -1,10 +1,9 @@ -var _ = require("lodash"); var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("topic", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { return; } @@ -31,7 +30,7 @@ module.exports = function(irc, network) { }); irc.on("topicsetby", function(data) { - var chan = _.find(network.channels, {name: data.channel}); + var chan = network.getChannel(data.channel); if (typeof chan === "undefined") { return; } diff --git a/src/plugins/irc-events/whois.js b/src/plugins/irc-events/whois.js index d10c7426..ea5430d1 100644 --- a/src/plugins/irc-events/whois.js +++ b/src/plugins/irc-events/whois.js @@ -1,11 +1,10 @@ -var _ = require("lodash"); var Chan = require("../../models/chan"); var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("whois", function(data) { - var chan = _.find(network.channels, {name: data.nick}); + var chan = network.getChannel(data.nick); if (typeof chan === "undefined") { chan = new Chan({ type: Chan.Type.QUERY,