From 7ae11babcbf2b6bbcfd2d39024ff650a714f075f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 26 Oct 2016 23:46:14 -0400 Subject: [PATCH 1/2] Add human-readable idle time in whois info --- client/views/actions/whois.tpl | 6 ++++++ src/plugins/irc-events/whois.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/client/views/actions/whois.tpl b/client/views/actions/whois.tpl index be0f8e22..d5c9a250 100644 --- a/client/views/actions/whois.tpl +++ b/client/views/actions/whois.tpl @@ -33,3 +33,9 @@ is away ({{whois.away}}) {{/if}} +{{#if whois.idle}} +
+ {{whois.nick}} + has been idle since {{localetime whois.idleTime}}. +
+{{/if}} diff --git a/src/plugins/irc-events/whois.js b/src/plugins/irc-events/whois.js index 86cdcaa9..c837dc1e 100644 --- a/src/plugins/irc-events/whois.js +++ b/src/plugins/irc-events/whois.js @@ -27,6 +27,9 @@ module.exports = function(irc, network) { text: "No such nick: " + data.nick }); } else { + // Absolute datetime in milliseconds since nick is idle + data.idleTime = Date.now() - data.idle * 1000; + msg = new Msg({ type: Msg.Type.WHOIS, whois: data From da2e286ff8a7690c37e8fbe526914e7fa2d91270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Thu, 27 Oct 2016 01:59:36 -0400 Subject: [PATCH 2/2] Use double-nick in whois on query to get idle time This queries server of the other user and not current user, which does not know idle time. See http://superuser.com/a/272069/208074. Override is done before command is being sent to the server: if a single argument is given to `/whois`, it is being repeated, otherwise the command is sent as is. --- src/client.js | 1 + src/plugins/inputs/whois.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/plugins/inputs/whois.js diff --git a/src/client.js b/src/client.js index a8270373..ceee4088 100644 --- a/src/client.js +++ b/src/client.js @@ -52,6 +52,7 @@ var inputs = [ "raw", "topic", "list", + "whois" ].reduce(function(plugins, name) { var path = "./plugins/inputs/" + name; var plugin = require(path); diff --git a/src/plugins/inputs/whois.js b/src/plugins/inputs/whois.js new file mode 100644 index 00000000..03573109 --- /dev/null +++ b/src/plugins/inputs/whois.js @@ -0,0 +1,15 @@ +"use strict"; + +exports.commands = ["whois"]; + +exports.input = function(network, chan, cmd, args) { + if (args.length === 1) { + // This queries server of the other user and not of the current user, which + // does not know idle time. + // See http://superuser.com/a/272069/208074. + network.irc.raw("WHOIS", args[0], args[0]); + } else { + // Re-assembling the command parsed in client.js + network.irc.raw(`${cmd} ${args.join(" ")}`); + } +};