diff --git a/src/url_metadata.js b/src/url_metadata.js index d2c58e1..3e46348 100644 --- a/src/url_metadata.js +++ b/src/url_metadata.js @@ -2,18 +2,24 @@ 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>/gi; - var match = re.exec(body); - if (match && match[1]) { - b.respond("[:link:](" + b.match[1] + ") _" + match[1] + "_"); +bot.global.text(/(https?:\/\/[^ ,\)"]*)/ig, (b) => { + // console.log(JSON.stringify(b.match, null, 2)); + for (url of b.match) { + // console.log(JSON.stringify(url, null, 2)); + if (!/(coa|pad)\.crapaud-fou\.org/.test(url)) { + request(url, (err, res, body) => { + if (!err) { + var re = /]*>([^<]*)<\/title>/gi; + var match = re.exec(body); + if (match && match[1]) { + // b.respondEnvelope({ attachments: [] }) + b.respond("[:link:](" + url + ") _" + match[1] + "_"); + } } - } - }); + }); + } } }, { id: 'get-url-metadata' }); +