From bc00fabb817ccf15882f9bd1413d71c659111efc Mon Sep 17 00:00:00 2001 From: amki Date: Sat, 24 May 2014 17:13:40 +0000 Subject: [PATCH] Roi requested the RSS module use goo.gl shortened links --- modules/rss/rss.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/rss/rss.js b/modules/rss/rss.js index 8f8be88..0060e57 100644 --- a/modules/rss/rss.js +++ b/modules/rss/rss.js @@ -39,12 +39,27 @@ var rss = function(dbot) { while (item = stream.read()) { if(item.pubdate.getTime() - feed.lastPosted > 0) { + var rss = item; feed.lastPosted = item.pubdate.getTime(); // FIXME: This doesn't work AT ALL dbot.db.feeds.splice(fid,1); dbot.db.feeds.push(feed); // - dbot.say(feed.server,feed.channel,"["+feed.name+"] ["+item.title+"] [Post by "+item.author+" in "+item.categories[0]+"] - "+item.link); + 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); + } + }); } } });