Browse Source

Removed the need for isFirstRun variable

Store the reference to the timer in a variable, so we can use it to cancel the timer in onDisconnect
shorten
benji7425 4 years ago
parent
commit
1763d7e068
  1. 17
      feed-bot.js

17
feed-bot.js

@ -10,10 +10,9 @@ 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 isFirstRun = true;
var DiscordClient = {
bot: null,
feedTimer = null,
startup: function () {
//check if we can connect to discordapp.com to authenticate the bot
Dns.resolve("discordapp.com", function (err) {
@ -33,18 +32,10 @@ var DiscordClient = {
});
},
onReady: function () {
if (isFirstRun) {
isFirstRun = false;
Log.info("Registered bot " + DiscordClient.bot.username + " - (" + DiscordClient.bot.id + ")");
Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds");
Log.info("Registered/connected bot " + DiscordClient.bot.username + " - (" + DiscordClient.bot.id + ")");
//set up the timer to check the feed
setInterval(Feed.checkAndPost, Config.pollingInterval);
}
else {
Log.info("DiscordClient reconnected!");
}
Log.info("Setting up timer to check feed every " + Config.pollingInterval + " milliseconds");
feedTimer = setInterval(Feed.checkAndPost, Config.pollingInterval); //set up the timer to check the feed
//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();

Loading…
Cancel
Save