Added an article extractor feature

This commit is contained in:
Brandon Rozek 2016-08-17 16:02:29 -04:00
parent 41628e583e
commit 8dc3c74343
3 changed files with 28 additions and 2 deletions

View file

@ -23,6 +23,7 @@ rozbot.extend(require('./lib/commands/calculate.js'));
rozbot.extend(require('./lib/commands/timer.js')); rozbot.extend(require('./lib/commands/timer.js'));
rozbot.extend(require('./lib/commands/search.js')); rozbot.extend(require('./lib/commands/search.js'));
rozbot.extend(require('./lib/commands/naturalSpeech.js')); rozbot.extend(require('./lib/commands/naturalSpeech.js'));
rozbot.extend(require('./lib/commands/extractArticle.js'));
rozbot.extend(require('./lib/commands/queryDuckDuckGo.js')); rozbot.extend(require('./lib/commands/queryDuckDuckGo.js'));
rozbot.respond(process.argv[2], rozbot.getUser("Command Line") || rozbot.addUser("Command Line", function(msg) { rozbot.respond(process.argv[2], rozbot.getUser("Command Line") || rozbot.addUser("Command Line", function(msg) {

View file

@ -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()
})
});

View file

@ -4,11 +4,13 @@
"description": "An IRC bot created by Brandon Rozek", "description": "An IRC bot created by Brandon Rozek",
"main": "bot.js", "main": "bot.js",
"dependencies": { "dependencies": {
"algebrite": "^0.2.20",
"cheerio": "^0.19.0", "cheerio": "^0.19.0",
"feed-read": "^0.0.1", "feed-read": "^0.0.1",
"fetch": "^1.0.0", "fetch": "^1.0.0",
"algebrite": "^0.2.20", "node-readability": "^2.2.0",
"promise-polyfill": "^2.1.4" "promise-polyfill": "^2.1.4",
"valid-url": "^1.0.9"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {