From: Darren Date: Sat, 24 Sep 2011 20:22:35 +0000 (+0100) Subject: Removed whois ending line, added seconds formatting X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a146029e5631112603ec64ba461f72372e928e9c;p=KiwiIRC.git Removed whois ending line, added seconds formatting --- diff --git a/js/front.events.js b/js/front.events.js index d7c95cb..a03b022 100644 --- a/js/front.events.js +++ b/js/front.events.js @@ -208,7 +208,15 @@ kiwi.front.events = { Tabview.getServerTab().addMsg(null, data.server, data.msg, 'motd'); }, onWhois: function (e, data) { - var d, tab; + var d, tab, idle_time = ''; + + if (data.end) return; + + if (typeof data.idle !== 'undefined'){ + idle_time = secondsToTime(parseInt(data.idle, 10)); + idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0"); + } + tab = Tabview.getCurrentTab(); if (data.msg) { tab.addMsg(null, data.nick, data.msg, 'whois'); @@ -216,9 +224,10 @@ kiwi.front.events = { d = new Date(); d.setTime(data.logon * 1000); d = d.toLocaleString(); - tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' second' + ((data.idle !== 1) ? 's' : '') + ', signed on ' + d, 'whois'); + + tab.addMsg(null, data.nick, 'idle for ' + idle_time + ', signed on ' + d, 'whois'); } else { - tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' seconds', 'whois'); + tab.addMsg(null, data.nick, 'idle for ' + idle_time, 'whois'); } }, onMode: function (e, data) { diff --git a/js/util.js b/js/util.js index a98cdc5..419c4a4 100644 --- a/js/util.js +++ b/js/util.js @@ -58,6 +58,25 @@ if (typeof String.prototype.lpad === 'undefined') { } + +function secondsToTime(secs){ + var hours = Math.floor(secs / (60 * 60)); + + var divisor_for_minutes = secs % (60 * 60); + var minutes = Math.floor(divisor_for_minutes / 60); + + var divisor_for_seconds = divisor_for_minutes % 60; + var seconds = Math.ceil(divisor_for_seconds); + + var obj = { + "h": hours, + "m": minutes, + "s": seconds + }; + return obj; +} + + /* PLUGINS Each function in each object is looped through and ran. The resulting text diff --git a/node/app.js b/node/app.js index b000948..7f0dec0 100644 --- a/node/app.js +++ b/node/app.js @@ -112,7 +112,8 @@ var ircNumerics = { this.parseIRCMessage = function (websocket, ircSocket, data) { /*global ircSocketDataHandler */ - var msg, regex, opts, options, opt, i, j, matches, nick, users, chan, channel, params, nicklist, caps, rtn, obj, tmp, namespace; + var msg, regex, opts, options, opt, i, j, matches, nick, users, chan, channel, + params, nicklist, caps, rtn, obj, tmp, namespace, whois_end = false; //regex = /^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@?([a-z0-9\.\-:\/]+)?) )?([a-z0-9]+)(?:(?: ([^:]+))?(?: :(.+))?)$/i; //regex = /^(?::(\S+) )?(\S+)(?: (?!:)(.+?))?(?: :(.+))?$/i; regex = /^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@?([a-z0-9\.\-:\/]+)?) )?(\S+)(?: (?!:)(.+?))?(?: :(.+))?$/i; @@ -173,13 +174,15 @@ this.parseIRCMessage = function (websocket, ircSocket, data) { websocket.sendClientEvent('options', {server: '', "options": ircSocket.IRC.options}); break; + + case ircNumerics.RPL_ENDOFWHOIS: + whois_end = true; case ircNumerics.RPL_WHOISUSER: case ircNumerics.RPL_WHOISSERVER: case ircNumerics.RPL_WHOISOPERATOR: - case ircNumerics.RPL_ENDOFWHOIS: case ircNumerics.RPL_WHOISCHANNELS: case ircNumerics.RPL_WHOISMODES: - websocket.sendClientEvent('whois', {server: '', nick: msg.params.split(" ", 3)[1], "msg": msg.trailing}); + websocket.sendClientEvent('whois', {server: '', nick: msg.params.split(" ", 3)[1], "msg": msg.trailing, end: whois_end}); break; case ircNumerics.RPL_LISTSTART: