From ab8e297769ab0f4770406d8ab775ab2c461ade2b Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 6 Mar 2013 13:02:02 +0000 Subject: [PATCH 1/3] add basic, hackish finger functionality --- modules/finger/README.md | 13 +++++++++++++ modules/finger/finger.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 modules/finger/README.md create mode 100644 modules/finger/finger.js diff --git a/modules/finger/README.md b/modules/finger/README.md new file mode 100644 index 0000000..549e850 --- /dev/null +++ b/modules/finger/README.md @@ -0,0 +1,13 @@ +## Finger + +Retrieves user information from a remote server. + +### Description +Uses the ``finger`` command to retrieve limited information on users. + + +### Commands +###~finger [username] +Returns the real name of the user specified. +### Dependencies +* ``npm install request`` diff --git a/modules/finger/finger.js b/modules/finger/finger.js new file mode 100644 index 0000000..84256e6 --- /dev/null +++ b/modules/finger/finger.js @@ -0,0 +1,29 @@ +/** + * Module Name: Finger + * Description: Returns the name of users via the Finger protocol + */ +var request = require('request'), + _ = require('underscore')._, + exec = require('child_process').exec; + +var finger = function(dbot) { + var commands = { + '~finger': function(event) { + var username = event.params[1]; + exec("finger -s " + username + "@central.aber.ac.uk",function(error,stdout,stderr){ + name = stdout.search("Name:"); + stdout = stdout.substring(name); + ret = stdout.search("Dir"); + stdout = stdout.substring(0,ret); + event.reply(stdout); + }); + } + }; + this.commands = commands; + + this.on = 'PRIVMSG'; +}; + +exports.fetch = function(dbot) { + return new finger(dbot); +}; From 3cdf3fd4176dddd42aaa2c3717111f845d3fc5f6 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 6 Mar 2013 13:10:54 +0000 Subject: [PATCH 2/3] add string functionality --- modules/finger/finger.js | 5 +++-- modules/finger/strings.json | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 modules/finger/strings.json diff --git a/modules/finger/finger.js b/modules/finger/finger.js index 84256e6..1334af6 100644 --- a/modules/finger/finger.js +++ b/modules/finger/finger.js @@ -11,11 +11,12 @@ var finger = function(dbot) { '~finger': function(event) { var username = event.params[1]; exec("finger -s " + username + "@central.aber.ac.uk",function(error,stdout,stderr){ + stdout = stdout.replace(/(\r\n|\n|\r)/gm,""); name = stdout.search("Name:"); stdout = stdout.substring(name); ret = stdout.search("Dir"); - stdout = stdout.substring(0,ret); - event.reply(stdout); + stdout = stdout.substring(6,ret); + event.reply(dbot.t("name",{user: username, name: stdout})); }); } }; diff --git a/modules/finger/strings.json b/modules/finger/strings.json new file mode 100644 index 0000000..5b79835 --- /dev/null +++ b/modules/finger/strings.json @@ -0,0 +1,5 @@ +{ + "name": { + "en": "{user} is {name}." + } +} From 9d277c7ac632b961ed2a0a1da4aa9c0050f6a8ef Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 6 Mar 2013 13:20:58 +0000 Subject: [PATCH 3/3] add hackish handling of non-existent users --- modules/finger/finger.js | 6 +++++- modules/finger/strings.json | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/finger/finger.js b/modules/finger/finger.js index 1334af6..f0a2e34 100644 --- a/modules/finger/finger.js +++ b/modules/finger/finger.js @@ -16,7 +16,11 @@ var finger = function(dbot) { stdout = stdout.substring(name); ret = stdout.search("Dir"); stdout = stdout.substring(6,ret); - event.reply(dbot.t("name",{user: username, name: stdout})); + if (stdout == "Welcom") { + event.reply(dbot.t("nonexistent",{user: username})); + } else { + event.reply(dbot.t("name",{user: username, name: stdout})); + } }); } }; diff --git a/modules/finger/strings.json b/modules/finger/strings.json index 5b79835..710e0f5 100644 --- a/modules/finger/strings.json +++ b/modules/finger/strings.json @@ -1,5 +1,8 @@ { "name": { "en": "{user} is {name}." + }, + "nonexistent": { + "en": "{user} not found." } }