From 6264e0d1f541c5692459450650633f39c0adf8df Mon Sep 17 00:00:00 2001 From: benji7425 Date: Mon, 15 May 2017 20:17:14 +0100 Subject: [PATCH 1/2] Add posting of links from multiple feeds --- config.json | 45 ++++++++++++++++++++++++--------------------- index.js | 24 ++++++++++++++++++------ 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/config.json b/config.json index 6723a9b..ebef3c9 100644 --- a/config.json +++ b/config.json @@ -1,23 +1,26 @@ { - "feedUrl": "https://www.youtube.com/feeds/videos.xml?user=EthosLab", - "channelID": "264420391282409473", - "serverID": "264420391282409473", - "pollingInterval": 5000, - "numLinksToCache": 10, - "messageDeleteDelay": 10000, - "youtubeMode": true, - "allowSubscriptions": true, - "subscribersRoleID": "272788856447959040", - "logFile": "./log", - "userCommands": { - "subscribe": "!subscribe", - "unsubscribe": "!unsubscribe", - "help": "!help" - }, - "developerCommands": { - "cacheList": "!cached" - }, - "developers": [ - "117966411548196870" - ] + "feedUrls": [ + "https://www.youtube.com/feeds/videos.xml?user=EthosLab", + "https://www.youtube.com/feeds/videos.xml?user=VintageBeef" + ], + "channelID": "264420391282409473", + "serverID": "264420391282409473", + "pollingInterval": 5000, + "numLinksToCache": 10, + "messageDeleteDelay": 10000, + "youtubeMode": true, + "allowSubscriptions": true, + "subscribersRoleID": "272788856447959040", + "logFile": "./log", + "userCommands": { + "subscribe": "!subscribe", + "unsubscribe": "!unsubscribe", + "help": "!help" + }, + "developerCommands": { + "cacheList": "!cached" + }, + "developers": [ + "117966411548196870" + ] } \ No newline at end of file diff --git a/index.js b/index.js index 8591530..8edbfcf 100644 --- a/index.js +++ b/index.js @@ -15,9 +15,14 @@ module.exports = { //set the interval function to check the feed intervalFunc = () => { - Feed.check((err, articles) => { + var callback = (err, articles) => { Links.validate(err, articles, (latestLink) => Actions.post(bot, latestLink)); - }); + }; + + if (Config.feedUrls.length > 1) + Feed.checkMultiple(Config.feedUrls, callback); + else + Feed.check(Config.feedUrls[0], callback); }; setInterval(() => { intervalFunc(); }, Config.pollingInterval); @@ -244,11 +249,18 @@ var Links = { }; var Feed = { - urlObj: Url.parse(Config.feedUrl), - check: function (callback) { - Dns.resolve(Feed.urlObj.host, function (err) { //check that we have an internet connection (well not exactly - check that we have a connection to the host of the feedUrl) + check: function (feedUrl, callback) { + Dns.resolve(Url.parse(feedUrl).host, function (err) { //check that we have an internet connection (well not exactly - check that we have a connection to the host of the feedUrl) if (err) Console.error("CONNECTION ERROR: Cannot resolve host.", err); - else FeedRead(Config.feedUrl, callback); + else FeedRead(feedUrl, callback); + }); + }, + checkMultiple: function (feedUrls, individualCallback) { + feedUrls.forEach((url) => { + Dns.resolve(Url.parse(url).host, (err) => { + if (err) Console.error("CONNECTION ERROR: Cannot resolve host.", err); + else FeedRead(url, individualCallback); + }); }); } }; From 93eea4e8f7c2ecd367a2b246d49b732128407eb0 Mon Sep 17 00:00:00 2001 From: benji7425 Date: Mon, 15 May 2017 20:19:15 +0100 Subject: [PATCH 2/2] Remove un-necessary spam --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index 8edbfcf..fe8a5a2 100644 --- a/index.js +++ b/index.js @@ -234,10 +234,7 @@ var Links = { return; //make sure the latest link hasn't been posted already - if (Links.isCached(latestLink)) { - Console.info("Didn't post new feed link because already detected as posted " + latestLink); - } - else { + if (!Links.isCached(latestLink)) { callback(latestLink); Links.cache(latestLink); //make sure the link is cached, so it doesn't get posted again