mirror of
https://github.com/Brandon-Rozek/Rozbot.git
synced 2024-11-21 20:46:28 -05:00
Added an article extractor feature
This commit is contained in:
parent
41628e583e
commit
8dc3c74343
3 changed files with 28 additions and 2 deletions
|
@ -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) {
|
||||||
|
|
23
lib/commands/extractArticle.js
Normal file
23
lib/commands/extractArticle.js
Normal 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()
|
||||||
|
})
|
||||||
|
});
|
|
@ -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": {
|
||||||
|
|
Loading…
Reference in a new issue