diff --git a/install b/install index 5f59661..c8f5611 100755 --- a/install +++ b/install @@ -14,7 +14,7 @@ then exit 1 fi -npm install node-units tvdb crypto-js 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash +npm install feedparser node-units tvdb crypto-js 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash cd public/ wget http://twitter.github.com/bootstrap/assets/bootstrap.zip diff --git a/jsbot b/jsbot index 750dacd..d551fe7 160000 --- a/jsbot +++ b/jsbot @@ -1 +1 @@ -Subproject commit 750dacdcd83f70ea11ac3f30e8cbbb5c4035b6af +Subproject commit d551fe778e87c47c380f2220d659aca2779f5820 diff --git a/modules/rss/README.md b/modules/rss/README.md new file mode 100644 index 0000000..b3fad47 --- /dev/null +++ b/modules/rss/README.md @@ -0,0 +1,14 @@ +## RSS + +RSS! + +### Description +This module reads RSS feeds and spams them to specific channels. + +### Commands + +#### ~addrssfeed [URL] +Adds RSS feed [URL] to be watched by current channel. + +#### ~delrssfeed [URL] +Deletes RSS feed [URL] from being watched by current channel. diff --git a/modules/rss/rss.js b/modules/rss/rss.js new file mode 100644 index 0000000..6385f05 --- /dev/null +++ b/modules/rss/rss.js @@ -0,0 +1,114 @@ +/** + * Module Name: RSS + * Description: Allows to read RSS feeds + */ +var FeedParser = require('feedparser') +, request = require('request'); + +var rss = function(dbot) { + this.pollInterval = 120000; + var self = this; + this.internalAPI = { + 'makeRequest': function(id,feed) { + var fid = id; + var req = request(feed.url); + var feedparser = new FeedParser(); + //dbot.say(feed.server,feed.channel,"Sending request for feed "+fid+" name "+feed.name+" lP:"+feed.lastPosted); + req.on('error', function (error) { + dbot.say(feed.server,feed.channel,"RSS: Request for RSS feed got an error: "+error+" Start self-destruct sequence."); + }); + req.on('response', function (res) { + var stream = this; + + if (res.statusCode != 200){ + dbot.say(feed.server,feed.channel,"RSS: RSS server returned status code "+res.statusCode+". Bastard."); + return; + } + + stream.pipe(feedparser); + }); + + feedparser.on('error', function(error) { + dbot.say(feed.server,feed.channel,"RSS: Feedparser encountered an error: "+error+";;; Inform administrator!"); + }); + feedparser.on('readable', function() { + // This is where the action is! + var stream = this + , meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance + , item; + + while (item = stream.read()) { + if(item.pubdate.getTime() - feed.lastPosted > 0) { + if(item.pubdate.getTime() > feed.newTime) { + feed.newTime = item.pubdate.getTime(); + } + var rss = item; + var options = { + uri: 'https://www.googleapis.com/urlshortener/v1/url', + method: 'POST', + json: { + "longUrl": rss.link + } + }; + + request(options, function (error, response, body) { + if (!error && response.statusCode == 200) { + dbot.say(feed.server,feed.channel,"["+feed.name+"] ["+rss.title+"] [Post by "+rss.author+" in "+rss.categories[0]+"] - "+body.id); + } else { + dbot.say(feed.server,feed.channel,"RSS: Request to shorten URL returned: "+body.id); + } + }); + } + } + }); + feedparser.on('end', function() { + feed.lastPosted = feed.newTime; + dbot.db.feeds[fid] = feed; + }); + }.bind(this), + 'checkFeeds': function() { + console.log("Checking feeds..."); + for(var i=0;i