add page title crawler
This commit is contained in:
parent
b50958c9cf
commit
f2ff773032
2 changed files with 19 additions and 0 deletions
1
index.js
1
index.js
|
@ -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
18
src/url_metadata.js
Normal 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'
|
||||
});
|
Loading…
Reference in a new issue