From 0d14bcf8d654732d78624514f1fc91bd6546d1f5 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Wed, 16 Oct 2013 15:24:00 +0100 Subject: [PATCH] Also use the ZNC-specific version of the `server-time` CAP Adds `znc.in/server-time-iso` to the list of requested CAPs and checks for it alongside `server-time` in commands.js --- server/irc/commands.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/server/irc/commands.js b/server/irc/commands.js index 7ac3c69..e281770 100644 --- a/server/irc/commands.js +++ b/server/irc/commands.js @@ -347,7 +347,7 @@ handlers = { channel = command.params[0]; } - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -366,7 +366,7 @@ handlers = { 'PART': function (command) { var time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -386,7 +386,7 @@ handlers = { 'KICK': function (command) { var time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -407,7 +407,7 @@ handlers = { 'QUIT': function (command) { var time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -427,7 +427,7 @@ handlers = { var namespace, time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -466,7 +466,7 @@ handlers = { 'NICK': function (command) { var time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -488,7 +488,7 @@ handlers = { // If we don't have an associated channel, no need to continue if (!command.params[0]) return; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -513,7 +513,7 @@ handlers = { modes = [], has_param, i, j, add, event, time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -576,7 +576,7 @@ handlers = { 'PRIVMSG': function (command) { var tmp, namespace, time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -641,7 +641,7 @@ handlers = { var request; // Which capabilities we want to enable - var want = ['multi-prefix', 'away-notify', 'server-time']; + var want = ['multi-prefix', 'away-notify', 'server-time', 'znc.in/server-time-iso']; if (this.irc_connection.password) { want.push('sasl'); @@ -713,7 +713,7 @@ handlers = { 'AWAY': function (command) { var time; - if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) { + if (capContainsAny.call(this, ['server-time', 'znc.in/server-time-iso']) && command.tags && command.tags.length > 0) { time = _.find(command.tags, function (tag) { return tag.tag === 'time'; }); @@ -966,3 +966,12 @@ function genericNotice (command, msg, is_error) { numeric: parseInt(command.command, 10) }); } + +function capContainsAny (caps) { + var intersection; + if (caps !instanceof Array) { + caps = [caps]; + } + intersection = _.intersection(this.irc_connection.cap.enabled, caps); + return intersection.length > 0; +} -- 2.25.1