Added proper check for first run, so we only execute startup once

This commit is contained in:
benji7425 2016-12-03 01:04:38 +00:00
parent 03e7712be0
commit 0d4e06c0cf

View file

@ -1,13 +1,16 @@
//external library imports
var Dns = require("dns"); //for connectivity checking var Dns = require("dns"); //for connectivity checking
var Url = require("url"); //for url parsing var Url = require("url"); //for url parsing
var Uri = require("urijs"); //for finding urls within message strings var Uri = require("urijs"); //for finding urls within message strings
var Discord = require("discord.io"); //for obvious reasons var Discord = require("discord.io"); //for obvious reasons
var FeedRead = require("feed-read"); //for rss feed reading 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 BotConfig = require("./bot-config.json"); //bot config file containing bot token
var Config = require("./config.json"); //config file containing other settings 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 = { var Bot = {
bot: null, bot: null,
@ -30,17 +33,21 @@ var Bot = {
}); });
}, },
onReady: function () { 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 Log.info("Registered bot " + this.bot.username + " - (" + this.bot.id + ")");
this.checkPastMessagesForLinks(); Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds");
Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds"); //set up the timer to check the feed
if (!isTimer) {
setInterval(Feed.checkAndPost, Config.pollingInterval); 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) { onDisconnect: function (err, code) {
//do a bunch of logging //do a bunch of logging