handle multiple urls on same message
This commit is contained in:
parent
7a2c6f607d
commit
03e20fced0
1 changed files with 16 additions and 10 deletions
|
@ -2,18 +2,24 @@
|
||||||
const bot = require('bbot');
|
const bot = require('bbot');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
|
||||||
bot.global.text(/(https?:\/\/.*)[, $]?/i, (b) => {
|
bot.global.text(/(https?:\/\/[^ ,\)"]*)/ig, (b) => {
|
||||||
if (!/coa\.crapaud-fou\.org/.test(b.match[1])) {
|
// console.log(JSON.stringify(b.match, null, 2));
|
||||||
request(b.match[1], (err, res, body) => {
|
for (url of b.match) {
|
||||||
if (!err) {
|
// console.log(JSON.stringify(url, null, 2));
|
||||||
var re = /<title[^>]*>([^<]*)<\/title>/gi;
|
if (!/(coa|pad)\.crapaud-fou\.org/.test(url)) {
|
||||||
var match = re.exec(body);
|
request(url, (err, res, body) => {
|
||||||
if (match && match[1]) {
|
if (!err) {
|
||||||
b.respond("[:link:](" + b.match[1] + ") _" + match[1] + "_");
|
var re = /<title[^>]*>([^<]*)<\/title>/gi;
|
||||||
|
var match = re.exec(body);
|
||||||
|
if (match && match[1]) {
|
||||||
|
// b.respondEnvelope({ attachments: [] })
|
||||||
|
b.respond("[:link:](" + url + ") _" + match[1] + "_");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: 'get-url-metadata'
|
id: 'get-url-metadata'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue