/** * Module Name: RSS * Description: Allows to read RSS feeds */ var FeedParser = require('feedparser') , request = require('request'); var rss = function(dbot) { 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) { dbot.say(server,channel,"Request got an error: "+error); }); req.on('response', function (res) { var stream = this; if (res.statusCode != 200){ dbot.say(server,channel,"Request had status code "+res.statusCode); return; } stream.pipe(feedparser); dbot.say(server,channel,"Request piped to feedparser!"); }); feedparser.on('error', function(error) { dbot.say(server,channel,"Feedparser got an error: "+error); }); 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,"@ "+item.pubdate+": ["+name+"] ["+item.title+"] [Post by "+item.author+" in "+item.categories[0]+"] - "+item.link); } }); }.bind(this), 'reloadFeeds': function() { console.log("rss: reloading feeds..."); for(var i=0;i