From a8283ba87a51f3d81072735dba2cc82df9b13a16 Mon Sep 17 00:00:00 2001 From: benji7425 Date: Wed, 2 Nov 2016 01:34:54 +0000 Subject: [PATCH 1/3] Removed silly and useless verboseLogging toggle --- feed-bot.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/feed-bot.js b/feed-bot.js index 1be4deb..f5f6211 100644 --- a/feed-bot.js +++ b/feed-bot.js @@ -67,17 +67,12 @@ Dns.resolve("discordapp.com", function (err) { cacheLink(url); return url; }); - } else if(message === "enableVerboseLogging"){ - verboseLogging = true; - } else if(message === "disableVerboseLogging"){ - verboseLogging = false; } }); } }); function checkFeedAndPost() { - if(verboseLogging) logEvent("Bot is currently " + (bot.connected ? "connected to" : "disconnected from") + " discord"); //check that we have an internet connection (well not exactly - check that we have a connection to the host of the feedUrl) Dns.resolve(url.host, function (err) { if (err) reportError("CONNECTION ERROR: Cannot resolve host (you are probably not connected to the internet). Details: " + (err.message || err)); From 599ed40db070ffdc474d072b7dae32207e35e00f Mon Sep 17 00:00:00 2001 From: benji7425 Date: Wed, 2 Nov 2016 01:48:48 +0000 Subject: [PATCH 2/3] Fixed disconnect error crash + added channel check on message detect --- feed-bot.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/feed-bot.js b/feed-bot.js index f5f6211..06cba3b 100644 --- a/feed-bot.js +++ b/feed-bot.js @@ -52,15 +52,16 @@ Dns.resolve("discordapp.com", function (err) { setInterval(checkFeedAndPost, Config.pollingInterval); }); - bot.on("disconnect", function(err, code){ - logEvent("Bot was disconnected. Code: " + code + ". Details: " + (err.message || err)); + bot.on("disconnect", function (err, code) { + logEvent("Bot was disconnected! " + code != null ? code : "No disconnect code provided"); + if (err) reportError("Bot disconnect error: " + (err.message || err)); logEvent("Trying to reconnect bot"); bot.connect(); }); bot.on("message", function (user, userID, channelID, message) { - //check if the message is a link, cache it if it is - if (linkRegExp.test(message) && (message !== latestFeedLink)) { + //check if the message contains a link, in the right channel, and not the latest link from the rss feed + if (channelID === Config.channelID && linkRegExp.test(message) && (message !== latestFeedLink)) { logEvent("Detected posted link: " + message); //detect the url inside the string, and cache it Uri.withinString(message, function (url) { @@ -92,16 +93,16 @@ function checkLinkAndPost(err, articles) { bot.sendMessage({ to: Config.channelID, message: latestLink - }, function(err, message){ + }, function (err, message) { reportError("ERROR: Failed to send message: " + (err.message || err) + " " + message); logEvent("Checking bot connectivity"); - if(bot.connected) + if (bot.connected) logEvent("Connectivity seems fine - I have no idea why the message didn't post"); - else{ + else { reportError("Bot appears to be disconnected! Attempting to reconnect...") bot.connect(); } - + }); cacheLink(latestLink); } From e84ebe197aa2433326a63479f9750393336d0200 Mon Sep 17 00:00:00 2001 From: benji7425 Date: Wed, 2 Nov 2016 01:50:01 +0000 Subject: [PATCH 3/3] Updated link detection log for clarity --- feed-bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feed-bot.js b/feed-bot.js index 06cba3b..9a56917 100644 --- a/feed-bot.js +++ b/feed-bot.js @@ -62,7 +62,7 @@ Dns.resolve("discordapp.com", function (err) { bot.on("message", function (user, userID, channelID, message) { //check if the message contains a link, in the right channel, and not the latest link from the rss feed if (channelID === Config.channelID && linkRegExp.test(message) && (message !== latestFeedLink)) { - logEvent("Detected posted link: " + message); + logEvent("Detected posted link in this message: " + message); //detect the url inside the string, and cache it Uri.withinString(message, function (url) { cacheLink(url);