coabot/src/url_metadata.js

18 lines
410 B
JavaScript
Raw Normal View History

2019-09-14 02:03:02 +00:00
const bot = require('bbot');
const request = require('request');
bot.global.text(/(https?:\/\/.*)[, $]?/i, (b) => {
request(b.match[1], (err, res, body) => {
if (!err) {
var re = /<title>([^<]*)<\/title>/gi;
var match = re.exec(body);
if (match && match[1]) {
2019-09-14 02:14:20 +00:00
b.respond("[:link:](" + b.match[1] + ") _" + match[1] + "_");
2019-09-14 02:03:02 +00:00
}
}
});
}, {
id: 'get-url-metadata'
});