diff --git a/modules/rss/rss.js b/modules/rss/rss.js index 6ded2c5..a9cf11e 100644 --- a/modules/rss/rss.js +++ b/modules/rss/rss.js @@ -2,26 +2,29 @@ * Module Name: RSS * Description: Allows to read RSS feeds */ -var FeedParser = require('feedparser') -, request = require('request') -, _ = require('underscore')._; +var FeedParser = require('feedparser'), + request = require('request'), + _ = require('underscore')._; 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); + var fid = id, + req = request(feed.url), + feedparser = new FeedParser(); + req.on('error', function (error) { + if(dbot.config.debugMode) { 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){ + if (res.statusCode !== 200){ dbot.say(feed.server,feed.channel,"RSS: RSS server returned status code "+res.statusCode+". Bastard."); return; } @@ -30,13 +33,16 @@ var rss = function(dbot) { }); feedparser.on('error', function(error) { - dbot.say(feed.server,feed.channel,"RSS: Feedparser encountered an error: "+error+";;; Inform administrator!"); + if(dbot.config.debugMode) { + 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; + 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) { @@ -72,16 +78,19 @@ var rss = function(dbot) { dbot.db.feeds[fid] = feed; }); }.bind(this), + 'checkFeeds': function() { console.log("Checking feeds..."); for(var i=0;i