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:
parent
3bfa3d58c3
commit
9b0cefe932
3
modules/link/config.json
Normal file
3
modules/link/config.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"autoTitle": false
|
||||||
|
}
|
@ -41,6 +41,18 @@ var link = function(dbot) {
|
|||||||
var urlMatches = event.message.match(urlRegex);
|
var urlMatches = event.message.match(urlRegex);
|
||||||
if(urlMatches !== null) {
|
if(urlMatches !== null) {
|
||||||
links[event.channel.name] = urlMatches[0];
|
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'
|
'on': 'PRIVMSG'
|
||||||
|
Loading…
Reference in New Issue
Block a user