add page title crawler

This commit is contained in:
mose 2019-09-14 10:03:02 +08:00
parent b50958c9cf
commit f2ff773032
2 changed files with 19 additions and 0 deletions

View File

@ -9,6 +9,7 @@ server.listen(process.env.PORT || 5000)
/** Add your bot logic here. Removing the imported examples. */
// require('./src/examples')
require('./src/url_metadata')
require('./src/reactions')
bot.start() // 🚀

18
src/url_metadata.js Normal file
View File

@ -0,0 +1,18 @@
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);
bot.logger.info(match[1]);
if (match && match[1]) {
b.respond(":link: _" + match[1] + "_");
}
}
});
}, {
id: 'get-url-metadata'
});