diff --git a/modules/rss/rss.js b/modules/rss/rss.js index 2c56f98..fc2db9f 100644 --- a/modules/rss/rss.js +++ b/modules/rss/rss.js @@ -6,40 +6,51 @@ var FeedParser = require('feedparser') , request = require('request'); var rss = function(dbot) { - this.feedparser = new FeedParser(); - this.feeds = []; + var self = this; + this.intervals = []; this.internalAPI = { 'makeRequest': function(server,channel,name,url) { dbot.say(server,channel,"Starting request for "+name+" with url "+url); var req = request(url); + var feedparser = new FeedParser(); req.on('error', function (error) { - // handle any request errors + dbot.say(server,channel,"Request got an error: "+error); }); req.on('response', function (res) { var stream = this; - if (res.statusCode != 200) return this.emit('error', new Error('Bad status code')); + if (res.statusCode != 200){ + dbot.say(server,channel,"Request had status code "+res.statusCode); + return; + } - stream.pipe(this.feedparser); + stream.pipe(feedparser); + dbot.say(server,channel,"Request piped to feedparser!"); }); - this.feedparser.on('error', function(error) { - // always handle errors + feedparser.on('error', function(error) { + dbot.say(server,channel,"Feedparser got an error: "+error); }); - this.feedparser.on('readable', function() { + 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()) { - dbot.say(server,channel,"FEED: "+item.title); + dbot.say(server,channel,"@ "+item.pubdate+": ["+name+"] ["+item.title+"] [Post by "+item.author+" in "+item.categories[0]+"] - "+item.link); } }); }.bind(this), 'reloadFeeds': function() { console.log("rss: reloading feeds..."); - // TODO actually reload feeds, set timers to refresh, refresh + for(var i=0;i "+item.title+" <- -> "+item.link+" <-"); - } - }); - */ - } + }; + this.onDestroy = function() { + for(var i=0;i