coabot/src/url_metadata.js

20 lines
488 B
JavaScript

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