2019-09-14 02:03:02 +00:00
|
|
|
|
|
|
|
const bot = require('bbot');
|
|
|
|
const request = require('request');
|
|
|
|
|
2019-09-14 13:29:56 +00:00
|
|
|
bot.global.text(/(https?:\/\/[^ ,\)"]*)/ig, (b) => {
|
2019-09-15 00:30:30 +00:00
|
|
|
// console.log(JSON.stringify(b.envelope.payload, null, 2));
|
2019-09-14 13:29:56 +00:00
|
|
|
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) {
|
2019-09-15 01:20:35 +00:00
|
|
|
console.log(JSON.stringify(res.request.uri.href, null, 2));
|
2019-09-14 13:29:56 +00:00
|
|
|
var re = /<title[^>]*>([^<]*)<\/title>/gi;
|
|
|
|
var match = re.exec(body);
|
|
|
|
if (match && match[1]) {
|
|
|
|
// b.respondEnvelope({ attachments: [] })
|
2019-09-15 00:30:30 +00:00
|
|
|
// b.envelope.payload.quickReply({ attachments: [] });
|
2019-09-15 01:20:35 +00:00
|
|
|
var extra = "";
|
|
|
|
var link = res.request.uri.href;
|
|
|
|
if (/youtube.com/.test(res.request.uri.href)) {
|
|
|
|
if (t = /[?&]v=([^&]+)/.exec(link)) {
|
|
|
|
link = "https://www.youtube.com/watch?v=" + t[1];
|
|
|
|
extra += " - [no-cookie](https://www.youtube-nocookie.com/embed/" + t[1] + ")";
|
|
|
|
extra += " - [invidio](https://invidio.us/watch?v=" + t[1] + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.respond("[:link:](" + url + ") _" + match[1] + "_" + extra);
|
2019-09-14 13:29:56 +00:00
|
|
|
}
|
2019-09-14 07:32:31 +00:00
|
|
|
}
|
2019-09-14 13:29:56 +00:00
|
|
|
});
|
|
|
|
}
|
2019-09-14 07:32:31 +00:00
|
|
|
}
|
2019-09-14 02:03:02 +00:00
|
|
|
}, {
|
|
|
|
id: 'get-url-metadata'
|
|
|
|
});
|