Fixed initial link detection caching links in the wrong order

This commit is contained in:
benji7425 2016-11-01 00:04:35 +00:00
parent 6515e32901
commit eb780182cb

View file

@ -12,9 +12,8 @@ var url = Url.parse(Config.feedUrl);
//placeholder for our bot - we need to check for connectivity before assigning this though
var bot;
var latestFeedLink = "";
var linkRegExp = new RegExp(["http", "https", "www"].join("|"));
var cachedLinks = [];
//caches a link so we can check again later
function cacheLink(link) {
@ -74,7 +73,8 @@ function checkLinkAndPost(err, articles) {
if (err) reportError("FEED ERROR: Error reading RSS feed. Details: " + (err.message || err));
else {
//get the latest link and check if it has already been posted and cached
var latestLink = articles[0].link.replace("https", "http"); //replace https with http for cheaty way of getting around matching issue
var latestLink = articles[0].link.replace("https", "http");
if (!cachedLinks.includes(latestLink)) {
logEvent("Attempting to post new link: " + latestLink);
bot.sendMessage({
@ -83,6 +83,10 @@ function checkLinkAndPost(err, articles) {
});
cacheLink(latestLink);
}
else if (latestFeedLink != latestLink)
logEvent("Didn't post new feed link because already detected as posted " + latestLink);
latestFeedLink = latestLink;
}
}
@ -97,7 +101,7 @@ function checkPreviousMessagesForLinks() {
if (err) reportError("Error fetching discord messages. Details: " + (err.message || err));
else {
logEvent("Pulled last " + messages.length + " messages, scanning for links");
var messageContents = messages.map((x) => { return x.content; });
var messageContents = messages.map((x) => { return x.content; }).reverse();
for (var message in messageContents) {
message = messageContents[message];
if (linkRegExp.test(message))