Search channel case insensitively

This commit is contained in:
Pavel Djundik 2016-03-20 16:28:47 +02:00 committed by Maxime Poulin
parent 40677e3248
commit e0fb454223
13 changed files with 21 additions and 22 deletions

View File

@ -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) {

View File

@ -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,

View File

@ -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;

View File

@ -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];
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,