From fd650dd981ef88ae8044460f47f3967bbffed4cc Mon Sep 17 00:00:00 2001 From: benji7425 Date: Mon, 2 Oct 2017 00:52:36 +0100 Subject: [PATCH] Prevent checking of feeds for guilds the bot is no longer in Plus fix a couple related issues --- app/index.js | 24 ++++++++++++++---------- app/models/guild-data.js | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/index.js b/app/index.js index 9c0d847..021ae80 100644 --- a/app/index.js +++ b/app/index.js @@ -10,14 +10,14 @@ const token = require("../" + process.argv[2]).token, const client = new Core.Client(token, dataFile, __dirname + "/commands", GuildData); client.on("beforeLogin", () => { - setInterval(() => checkFeedsInGuilds(client.guildsData), Config.feedCheckIntervalSec * 1000); + setInterval(() => checkFeedsInGuilds(), Config.feedCheckIntervalSec * 1000); }); client.on("ready", () => { doUpgradeJSON(); - parseLinksInGuilds(client.guilds, client.guildsData) - .then(() => checkFeedsInGuilds(client.guildsData)); + parseLinksInGuilds() + .then(() => checkFeedsInGuilds()); client.on("message", message => { const guildData = client.guildsData[message.guild.id]; @@ -32,16 +32,20 @@ client.on("ready", () => { client.bootstrap(); //INTERNAL FUNCTIONS// -function checkFeedsInGuilds(guildsData) { - Object.keys(guildsData).forEach(key => guildsData[key].checkFeeds(client.guilds)); +function checkFeedsInGuilds() { + client.guilds.forEach(guild => { + const guildData = client.guildsData[guild.id]; + if (guildData) + guildData.checkFeeds(guild); + }); } -function parseLinksInGuilds(guilds, guildsData) { +function parseLinksInGuilds() { const promises = []; - for (let guildId of guilds.keys()) { - const guildData = guildsData[guildId]; + for (let guildId of client.guilds.keys()) { + const guildData = client.guildsData[guildId]; if (guildData) - promises.push(guildData.cachePastPostedLinks(guilds.get(guildId))); + promises.push(guildData.cachePastPostedLinks(client.guilds.get(guildId))); } return Promise.all(promises); } @@ -60,7 +64,7 @@ function doUpgradeJSON() { if (feed.channelName) { feed.channelID = client.guilds.get(id).channels.find(x => x.name.toLowerCase() === feed.channelName.toLowerCase()).id; - delete feed.channelID; + delete feed.channelName; } }); }); diff --git a/app/models/guild-data.js b/app/models/guild-data.js index 95a5d1f..e6e5b68 100644 --- a/app/models/guild-data.js +++ b/app/models/guild-data.js @@ -21,7 +21,7 @@ module.exports = class GuildData extends Core.BaseGuildData { return Promise.all(promises); } - checkFeeds(guilds) { - this.feeds.forEach(feed => feed.fetchLatest(guilds.get(this.id))); + checkFeeds(guild) { + this.feeds.forEach(feed => feed.fetchLatest(guild)); } }; \ No newline at end of file