Browse Source

Add posting of links from multiple feeds

shorten
benji7425 4 years ago
parent
commit
6264e0d1f5
  1. 45
      config.json
  2. 24
      index.js

45
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"
]
}

24
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);
});
});
}
};

Loading…
Cancel
Save