From 0d4e06c0cfa1da43fe85be828a5345bd063c74d9 Mon Sep 17 00:00:00 2001 From: benji7425 Date: Sat, 3 Dec 2016 01:04:38 +0000 Subject: [PATCH] Added proper check for first run, so we only execute startup once --- feed-bot.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/feed-bot.js b/feed-bot.js index 52582d3..24852b0 100644 --- a/feed-bot.js +++ b/feed-bot.js @@ -1,13 +1,16 @@ +//external library imports var Dns = require("dns"); //for connectivity checking var Url = require("url"); //for url parsing var Uri = require("urijs"); //for finding urls within message strings var Discord = require("discord.io"); //for obvious reasons var FeedRead = require("feed-read"); //for rss feed reading + +//my imports +var Log = require("./log.js"); //some very simple logging functions I made var BotConfig = require("./bot-config.json"); //bot config file containing bot token var Config = require("./config.json"); //config file containing other settings -var Log = require("./log.js"); //some very simple logging functions I made -var isTimer = false; +var IS_FIRST_RUN = true; var Bot = { bot: null, @@ -30,17 +33,21 @@ var Bot = { }); }, onReady: function () { - Log.info("Registered bot " + this.bot.username + " - (" + this.bot.id + ")"); + if (IS_FIRST_RUN) { + IS_FIRST_RUN = false; - //as we don't have any links cached, we need to check recent messages - this.checkPastMessagesForLinks(); + Log.info("Registered bot " + this.bot.username + " - (" + this.bot.id + ")"); + Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds"); - Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds"); - - if (!isTimer) { + //set up the timer to check the feed setInterval(Feed.checkAndPost, Config.pollingInterval); - isTimer = true; } + else { + Log.info("Bot reconnected!"); + } + + //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 + this.checkPastMessagesForLinks(); }, onDisconnect: function (err, code) { //do a bunch of logging