From 9b0cefe932e6e7a128b93701e8a65912266060a8 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 27 Dec 2012 23:18:41 +0000 Subject: [PATCH] auto title option for link --- modules/link/config.json | 3 +++ modules/link/link.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 modules/link/config.json diff --git a/modules/link/config.json b/modules/link/config.json new file mode 100644 index 0000000..d1a8210 --- /dev/null +++ b/modules/link/config.json @@ -0,0 +1,3 @@ +{ + "autoTitle": false +} diff --git a/modules/link/link.js b/modules/link/link.js index b9c5eaf..d0bf2d9 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -41,6 +41,18 @@ var link = function(dbot) { var urlMatches = event.message.match(urlRegex); if(urlMatches !== null) { links[event.channel.name] = urlMatches[0]; + + if(dbot.config.link.autoTitle == true) { + request(urlMatches[0], function (error, response, body) { + if(!error && response.statusCode == 200) { + body = body.replace(/(\r\n|\n\r|\n)/gm, " "); + var title = body.valMatch(/(.*)<\/title>/, 2); + if(title) { + event.reply(title[1]); + } + } + }); + } } }, 'on': 'PRIVMSG'