3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00

auto title option for link

This commit is contained in:
reality 2012-12-27 23:18:41 +00:00
parent 3bfa3d58c3
commit 9b0cefe932
2 changed files with 15 additions and 0 deletions

3
modules/link/config.json Normal file
View File

@ -0,0 +1,3 @@
{
"autoTitle": false
}

View File

@ -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>(.*)<\/title>/, 2);
if(title) {
event.reply(title[1]);
}
}
});
}
}
},
'on': 'PRIVMSG'