From 02b400266daa98dfb965d29ea5c8ad722385fcab Mon Sep 17 00:00:00 2001 From: benji7425 Date: Sat, 29 Jul 2017 20:33:05 +0100 Subject: [PATCH] Add method to iterate over all guild to update their feed caches --- app/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/index.js b/app/index.js index 00dcad7..90894e9 100644 --- a/app/index.js +++ b/app/index.js @@ -2,6 +2,7 @@ const FileSystem = require("fs"); //external lib imports +const Dicsord = require("discord.js"); const JSONFile = require("jsonfile"); //app component imports @@ -13,11 +14,21 @@ const SAVE_FILE = "./guilds.json"; module.exports = (client) => { const guildsData = FileSystem.existsSync(SAVE_FILE) ? parseJSON(JSONFile.readFileSync(SAVE_FILE)) : {}; //pull saved data from file + parseLinksInAllGuilds(client.guilds, guildsData); + //set up an interval to check all the feeds //set up an on message handler to detect when links are posted }; +function parseLinksInAllGuilds(guilds, guildsData) { + for (let guild of guilds) { + const guildData = guildsData[guild.id]; + if (guildData) + guildData.cachePastPostedLinks(); + } +} + function parseJSON(json) { const guildIDs = Object.keys(json); guildIDs.forEach(guildID => { guildIDs[guildID] = new GuildData(guildIDs[guildID]); });