mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
dont repeat items with the same title within a bound of 30
This commit is contained in:
parent
09e91bf817
commit
3a2374ad59
@ -8,6 +8,8 @@ var FeedParser = require('feedparser'),
|
|||||||
|
|
||||||
var rss = function(dbot) {
|
var rss = function(dbot) {
|
||||||
this.pollInterval = 120000;
|
this.pollInterval = 120000;
|
||||||
|
this.titleCache = [];
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
'makeRequest': function(id,feed) {
|
'makeRequest': function(id,feed) {
|
||||||
@ -50,26 +52,32 @@ var rss = function(dbot) {
|
|||||||
feed.newTime = item.pubdate.getTime();
|
feed.newTime = item.pubdate.getTime();
|
||||||
}
|
}
|
||||||
var rss = item;
|
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(!_.include(self.titleCache, rss.title)) {
|
||||||
if (!error && response.statusCode === 200) {
|
var options = {
|
||||||
var rString = "["+feed.name+"] ["+rss.title+"] ";
|
uri: 'https://www.googleapis.com/urlshortener/v1/url',
|
||||||
if(rss.author !== null && !_.isUndefined(rss.categories[0])) {
|
method: 'POST',
|
||||||
rString += "[Post by "+rss.author+" in "+rss.categories[0]+"] ";
|
json: {
|
||||||
|
"longUrl": rss.link
|
||||||
}
|
}
|
||||||
rString += "- "+body.id;
|
};
|
||||||
dbot.say(feed.server,feed.channel, rString);
|
|
||||||
} else {
|
request(options, function (error, response, body) {
|
||||||
dbot.say(feed.server,feed.channel,"RSS: Request to shorten URL returned: "+body.id);
|
if (!error && response.statusCode === 200) {
|
||||||
|
var rString = "["+feed.name+"] ["+rss.title+"] ";
|
||||||
|
if(rss.author !== null && !_.isUndefined(rss.categories[0])) {
|
||||||
|
rString += "[Post by "+rss.author+" in "+rss.categories[0]+"] ";
|
||||||
|
}
|
||||||
|
rString += "- "+body.id;
|
||||||
|
dbot.say(feed.server,feed.channel, rString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(self.titleCache.length > 30) {
|
||||||
|
self.titleCache.splice(0, 1);
|
||||||
}
|
}
|
||||||
});
|
self.titleCache.push(feed.title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user