Fixed FeedRead being called too early in the feed checking call chain
This commit is contained in:
parent
76819d658a
commit
9c89b489d5
12
feed-bot.js
12
feed-bot.js
|
@ -37,9 +37,9 @@ var DiscordClient = {
|
||||||
DiscordClient.checkPastMessagesForLinks(); //we need to check past messages for links on startup, but also on reconnect because we don't know what has happened during the downtime
|
DiscordClient.checkPastMessagesForLinks(); //we need to check past messages for links on startup, but also on reconnect because we don't know what has happened during the downtime
|
||||||
|
|
||||||
intervalFunc = () => {
|
intervalFunc = () => {
|
||||||
Feed.check(FeedRead(Config.feedUrl, (err, articles) => {
|
Feed.check((err, articles) => {
|
||||||
Links.validate(err, articles, DiscordClient.post);
|
Links.validate(err, articles, DiscordClient.post);
|
||||||
}));
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onDisconnect: function (err, code) {
|
onDisconnect: function (err, code) {
|
||||||
|
@ -160,7 +160,7 @@ var Links = {
|
||||||
validate: function (err, articles, callback) {
|
validate: function (err, articles, callback) {
|
||||||
if (err) Log.error("FEED ERROR: Error reading RSS feed.", err);
|
if (err) Log.error("FEED ERROR: Error reading RSS feed.", err);
|
||||||
else {
|
else {
|
||||||
var latestLink = Links.standardise(articles[0].link); //get the latest link and check if it has already been posted and cached
|
var latestLink = Links.standardise(Config.youtubeMode ? YouTube.url.createShareUrl(articles[0].link) : articles[0].link); //get the latest link and convert to share url if youtube mode
|
||||||
|
|
||||||
//make sure we don't spam the latest link
|
//make sure we don't spam the latest link
|
||||||
if (latestLink == Links.latestFeedLink)
|
if (latestLink == Links.latestFeedLink)
|
||||||
|
@ -172,8 +172,6 @@ var Links = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.youtubeMode) latestLink = YouTube.url.createShareUrl(latestLink);
|
|
||||||
|
|
||||||
callback(latestLink);
|
callback(latestLink);
|
||||||
|
|
||||||
Links.cache(latestLink); //make sure the link is cached, so it doesn't get posted again
|
Links.cache(latestLink); //make sure the link is cached, so it doesn't get posted again
|
||||||
|
@ -187,7 +185,7 @@ var Feed = {
|
||||||
check: function (callback) {
|
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)
|
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)
|
||||||
if (err) Log.error("CONNECTION ERROR: Cannot resolve host.", err);
|
if (err) Log.error("CONNECTION ERROR: Cannot resolve host.", err);
|
||||||
else callback();
|
else FeedRead(Config.feedUrl, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -197,5 +195,5 @@ var intervalFunc = () => { }; //do nothing by default
|
||||||
//IIFE to kickstart the bot when the app loads
|
//IIFE to kickstart the bot when the app loads
|
||||||
(function () {
|
(function () {
|
||||||
DiscordClient.startup();
|
DiscordClient.startup();
|
||||||
setInterval(intervalFunc, Config.pollingInterval);
|
setInterval(() => { intervalFunc(); }, Config.pollingInterval);
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue