diff --git a/index.js b/index.js index c9cf761..85003cb 100644 --- a/index.js +++ b/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() // 🚀 diff --git a/src/url_metadata.js b/src/url_metadata.js new file mode 100644 index 0000000..9759d8b --- /dev/null +++ b/src/url_metadata.js @@ -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>/gi; + var match = re.exec(body); + bot.logger.info(match[1]); + if (match && match[1]) { + b.respond(":link: _" + match[1] + "_"); + } + } + }); +}, { + id: 'get-url-metadata' +});