diff --git a/example.js b/example.js index 6fbf524..375c8b4 100644 --- a/example.js +++ b/example.js @@ -23,6 +23,7 @@ rozbot.extend(require('./lib/commands/calculate.js')); rozbot.extend(require('./lib/commands/timer.js')); rozbot.extend(require('./lib/commands/search.js')); rozbot.extend(require('./lib/commands/naturalSpeech.js')); +rozbot.extend(require('./lib/commands/extractArticle.js')); rozbot.extend(require('./lib/commands/queryDuckDuckGo.js')); rozbot.respond(process.argv[2], rozbot.getUser("Command Line") || rozbot.addUser("Command Line", function(msg) { diff --git a/lib/commands/extractArticle.js b/lib/commands/extractArticle.js new file mode 100644 index 0000000..dbd6e37 --- /dev/null +++ b/lib/commands/extractArticle.js @@ -0,0 +1,23 @@ +var Command = require('./Command.js'); +var grabTokens = require('../helpers/grabTokens.js'); +var read = require('node-readability'); +var validUrl = require('valid-url') + +var condition = function(text) { + var tokens = grabTokens(text); + return tokens.contain('extract'); +} + +module.exports = new Command("ExtractArticle", condition, function(text, send, userData) { + var tokens = grabTokens(text); + var url = tokens.find(function(element, index, array) { + if (validUrl.isUri(element)) { + return true; + } + return false; + }); + read(url, function(err, article, meta) { + send(article.textBody); + article.close() + }) +}); diff --git a/package.json b/package.json index da74c0f..dbc8e61 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,13 @@ "description": "An IRC bot created by Brandon Rozek", "main": "bot.js", "dependencies": { + "algebrite": "^0.2.20", "cheerio": "^0.19.0", "feed-read": "^0.0.1", "fetch": "^1.0.0", - "algebrite": "^0.2.20", - "promise-polyfill": "^2.1.4" + "node-readability": "^2.2.0", + "promise-polyfill": "^2.1.4", + "valid-url": "^1.0.9" }, "devDependencies": {}, "scripts": {