Server-side support for server-time CAP
authorJack Allnutt <jack@allnutt.eu>
Sat, 28 Sep 2013 16:53:40 +0000 (17:53 +0100)
committerJack Allnutt <jack@allnutt.eu>
Sat, 28 Sep 2013 16:53:40 +0000 (17:53 +0100)
server/irc/channel.js
server/irc/commands.js
server/irc/user.js

index fcdeec28a4db9bc19e55b27bb30d57d74fc514d2..1a8c6d9103a0780958e42a5e52dd1fc0651bf054 100644 (file)
@@ -46,7 +46,8 @@ function onJoin(event) {
         channel: this.name,
         nick: event.nick,
         ident: event.ident,
-        hostname: event.hostname
+        hostname: event.hostname,
+        time: event.time
     });
 
     // If we've just joined this channel then request get a nick list
@@ -62,7 +63,8 @@ function onPart(event) {
         ident: event.ident,
         hostname: event.hostname,
         channel: this.name,
-        message: event.message
+        message: event.message,
+        time: event.time
     });
 }
 
@@ -74,7 +76,8 @@ function onKick(event) {
         ident: event.ident,
         hostname: event.hostname,
         channel: this.name,
-        message: event.message
+        message: event.message,
+        time: event.time
     });
 }
 
@@ -84,7 +87,8 @@ function onQuit(event) {
         nick: event.nick,
         ident: event.ident,
         hostname: event.hostname,
-        message: event.message
+        message: event.message,
+        time: event.time
     });
 }
 
@@ -95,7 +99,8 @@ function onMsg(event) {
         ident: event.ident,
         hostname: event.hostname,
         channel: this.name,
-        msg: event.msg
+        msg: event.msg,
+        time: event.time
     });
 }
 
@@ -107,7 +112,8 @@ function onNotice(event) {
         ident: event.ident,
         hostname: event.hostname,
         target: event.target,
-        msg: event.msg
+        msg: event.msg,
+        time: event.time
     });
 }
 
@@ -119,7 +125,8 @@ function onCtcpRequest(event) {
         hostname: event.hostname,
         target: event.target,
         type: event.type,
-        msg: event.msg
+        msg: event.msg,
+        time: event.time
     });
 }
 
@@ -131,7 +138,8 @@ function onCtcpResponse(event) {
         hostname: event.hostname,
         target: event.target,
         type: event.type,
-        msg: event.msg
+        msg: event.msg,
+        time: event.time
     });
 }
 
@@ -172,7 +180,8 @@ function onTopic(event) {
     this.irc_connection.clientEvent('topic', {
         nick: event.nick,
         channel: this.name,
-        topic: event.topic
+        topic: event.topic,
+        time: event.time
     });
 }
 
@@ -208,6 +217,7 @@ function onMode(event) {
     this.irc_connection.clientEvent('mode', {
         target: event.target,
         nick: event.nick,
-        modes: event.modes
+        modes: event.modes,
+        time: event.time
     });
 }
index e37d454491e79d14cfa7ff8b5735dd98710cf611..7ac3c69b73591e96841693d8aa7a1e27c11f6272 100644 (file)
@@ -340,53 +340,100 @@ handlers = {
     },
 
     'JOIN': function (command) {
-        var channel;
+        var channel, time;
         if (typeof command.trailing === 'string' && command.trailing !== '') {
             channel = command.trailing;
         } else if (typeof command.params[0] === 'string' && command.params[0] !== '') {
             channel = command.params[0];
         }
 
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('channel ' + channel + ' join', {
             nick: command.nick,
             ident: command.ident,
             hostname: command.hostname,
-            channel: channel
+            channel: channel,
+            time: time
         });
     },
 
     'PART': function (command) {
+        var time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('channel ' + command.params[0] + ' part', {
             nick: command.nick,
             ident: command.ident,
             hostname: command.hostname,
             channel: command.params[0],
-            message: command.trailing
+            message: command.trailing,
+            time: time
         });
     },
 
     'KICK': function (command) {
+        var time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('channel ' + command.params[0] + ' kick', {
             kicked: command.params[1],
             nick: command.nick,
             ident: command.ident,
             hostname: command.hostname,
             channel: command.params[0],
-            message: command.trailing
+            message: command.trailing,
+            time: time
         });
     },
 
     'QUIT': function (command) {
+        var time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('user ' + command.nick + ' quit', {
             nick: command.nick,
             ident: command.ident,
             hostname: command.hostname,
-            message: command.trailing
+            message: command.trailing,
+            time: time
         });
     },
 
     'NOTICE': function (command) {
-        var namespace;
+        var namespace,
+            time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
 
         if ((command.trailing.charAt(0) === String.fromCharCode(1)) && (command.trailing.charAt(command.trailing.length - 1) === String.fromCharCode(1))) {
             // It's a CTCP response
@@ -396,7 +443,8 @@ handlers = {
                 ident: command.ident,
                 hostname: command.hostname,
                 channel: command.params[0],
-                msg: command.trailing.substring(1, command.trailing.length - 1)
+                msg: command.trailing.substring(1, command.trailing.length - 1),
+                time: time
             });
         } else {
             namespace = (command.params[0].toLowerCase() == this.irc_connection.nick.toLowerCase() || command.params[0] == '*') ?
@@ -409,31 +457,52 @@ handlers = {
                 ident: command.ident,
                 hostname: command.hostname,
                 target: command.params[0],
-                msg: command.trailing
+                msg: command.trailing,
+                time: time
             });
         }
     },
 
     'NICK': function (command) {
+        var time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('user ' + command.nick + ' nick', {
             nick: command.nick,
             ident: command.ident,
             hostname: command.hostname,
-            newnick: command.trailing || command.params[0]
+            newnick: command.trailing || command.params[0],
+            time: time
         });
     },
 
     'TOPIC': function (command) {
+        var time;
+
         // 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) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         var channel = command.params[0],
             topic = command.trailing || '';
 
         this.irc_connection.emit('channel ' + channel + ' topic', {
             nick: command.nick,
             channel: channel,
-            topic: topic
+            topic: topic,
+            time: time
         });
     },
 
@@ -442,7 +511,14 @@ handlers = {
             prefixes = this.irc_connection.options.PREFIX || [],
             always_param = (chanmodes[0] || '').concat((chanmodes[1] || '')),
             modes = [],
-            has_param, i, j, add, event;
+            has_param, i, j, add, event, time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
 
         prefixes = _.reduce(prefixes, function (list, prefix) {
             list.push(prefix.mode);
@@ -492,20 +568,40 @@ handlers = {
         this.irc_connection.emit(event, {
             target: command.params[0],
             nick: command.nick || command.prefix || '',
-            modes: modes
+            modes: modes,
+            time: time
         });
     },
 
     'PRIVMSG': function (command) {
-        var tmp, namespace;
+        var tmp, namespace, time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         if ((command.trailing.charAt(0) === String.fromCharCode(1)) && (command.trailing.charAt(command.trailing.length - 1) === String.fromCharCode(1))) {
             //CTCP request
             if (command.trailing.substr(1, 6) === 'ACTION') {
-                this.irc_connection.clientEvent('action', {nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing.substring(8, command.trailing.length - 1)});
+                this.irc_connection.clientEvent('action', {
+                    nick: command.nick,
+                    ident: command.ident,
+                    hostname: command.hostname,
+                    channel: command.params[0],
+                    msg: command.trailing.substring(8, command.trailing.length - 1),
+                    time: time
+                });
             } else if (command.trailing.substr(1, 4) === 'KIWI') {
                 tmp = command.trailing.substring(6, command.trailing.length - 1);
                 namespace = tmp.split(' ', 1)[0];
-                this.irc_connection.clientEvent('kiwi', {namespace: namespace, data: tmp.substr(namespace.length + 1)});
+                this.irc_connection.clientEvent('kiwi', {
+                    namespace: namespace,
+                    data: tmp.substr(namespace.length + 1),
+                    time: time
+                });
             } else if (command.trailing.substr(1, 7) === 'VERSION') {
                 this.irc_connection.write('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1));
             } else if (command.trailing.substr(1, 6) === 'SOURCE') {
@@ -520,7 +616,8 @@ handlers = {
                     hostname: command.hostname,
                     target: command.params[0],
                     type: (command.trailing.substring(1, command.trailing.length - 1).split(' ') || [null])[0],
-                    msg: command.trailing.substring(1, command.trailing.length - 1)
+                    msg: command.trailing.substring(1, command.trailing.length - 1),
+                    time: time
                 });
             }
         } else {
@@ -531,7 +628,8 @@ handlers = {
                 ident: command.ident,
                 hostname: command.hostname,
                 channel: command.params[0],
-                msg: command.trailing
+                msg: command.trailing,
+                time: time
             });
         }
     },
@@ -543,7 +641,7 @@ handlers = {
         var request;
 
         // Which capabilities we want to enable
-        var want = ['multi-prefix', 'away-notify'];
+        var want = ['multi-prefix', 'away-notify', 'server-time'];
 
         if (this.irc_connection.password) {
             want.push('sasl');
@@ -613,9 +711,19 @@ handlers = {
     },
 
     'AWAY': function (command) {
+        var time;
+
+        if (_.contains(this.irc_connection.cap.enabled, 'server-time') && command.tags && command.tags.length > 0) {
+            time = _.find(command.tags, function (tag) {
+                return tag.tag === 'time';
+            });
+            time = time ? time.value : undefined;
+        }
+
         this.irc_connection.emit('user ' + command.nick + ' away', {
             nick: command.nick,
-            msg: command.trailing
+            msg: command.trailing,
+            time: time
         });
     },
 
index 387b7f1534901bdb1e73f9e6be7e793a2a29499d..1417d95f22537e7d0bb1528aab77d3510d8ce7b6 100755 (executable)
@@ -45,7 +45,8 @@ function onNick(event) {
         nick: event.nick,\r
         ident: event.ident,\r
         hostname: event.hostname,\r
-        newnick: event.newnick\r
+        newnick: event.newnick,\r
+        time: event.time\r
     });\r
 \r
     // TODO: uncomment when using an IrcUser per nick\r
@@ -57,7 +58,8 @@ function onNick(event) {
 function onAway(event) {\r
     this.irc_connection.clientEvent('away', {\r
         nick: event.nick,\r
-        msg: event.msg\r
+        msg: event.msg,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -66,7 +68,8 @@ function onQuit(event) {
         nick: event.nick,\r
         ident: event.ident,\r
         hostname: event.hostname,\r
-        message: event.trailing\r
+        message: event.trailing,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -177,7 +180,8 @@ function onNotice(event) {
         ident: event.ident,\r
         hostname: event.hostname,\r
         target: event.target,\r
-        msg: event.msg\r
+        msg: event.msg,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -187,7 +191,8 @@ function onCtcpResponse(event) {
         ident: event.ident,\r
         hostname: event.hostname,\r
         channel: event.channel,\r
-        msg: event.msg\r
+        msg: event.msg,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -197,7 +202,8 @@ function onPrivmsg(event) {
         ident: event.ident,\r
         hostname: event.hostname,\r
         channel: event.channel,\r
-        msg: event.msg\r
+        msg: event.msg,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -208,7 +214,8 @@ function onCtcpRequest(event) {
         hostname: event.hostname,\r
         target: event.target,\r
         type: event.type,\r
-        msg: event.msg\r
+        msg: event.msg,\r
+        time: event.time\r
     });\r
 }\r
 \r
@@ -216,6 +223,7 @@ function onMode(event) {
     this.irc_connection.clientEvent('mode', {\r
         target: event.target,\r
         nick: event.nick,\r
-        modes: event.modes\r
+        modes: event.modes,\r
+        time: event.time\r
     });\r
 }\r