diff --git a/app/index.js b/app/index.js index d830bc3..00dcad7 100644 --- a/app/index.js +++ b/app/index.js @@ -1,9 +1,24 @@ +//node imports +const FileSystem = require("fs"); + +//external lib imports +const JSONFile = require("jsonfile"); + +//app component imports +const GuildData = require("./models/guild-data.js"); + +const SAVE_FILE = "./guilds.json"; + //acts as on ready function module.exports = (client) => { - client.on("message", message => message.reply("Hello!")); - //check messages in channel for links posted since last online - + const guildsData = FileSystem.existsSync(SAVE_FILE) ? parseJSON(JSONFile.readFileSync(SAVE_FILE)) : {}; //pull saved data from file + //set up an interval to check all the feeds //set up an on message handler to detect when links are posted -}; \ No newline at end of file +}; + +function parseJSON(json) { + const guildIDs = Object.keys(json); + guildIDs.forEach(guildID => { guildIDs[guildID] = new GuildData(guildIDs[guildID]); }); +} \ No newline at end of file diff --git a/app/models/feed.js b/app/models/feed.js new file mode 100644 index 0000000..f9281a1 --- /dev/null +++ b/app/models/feed.js @@ -0,0 +1,7 @@ +module.exports = class Feed{ + constructor({link, channelName, roleID}){ + this.link = link; + this.channelName = channelName; + this.roleID = roleID; + } +}; \ No newline at end of file diff --git a/app/models/guild-data.js b/app/models/guild-data.js new file mode 100644 index 0000000..6ee120c --- /dev/null +++ b/app/models/guild-data.js @@ -0,0 +1,8 @@ +const Feed = require("./feed.js"); + +module.exports = class GuildData { + constructor({id, feeds}) { + this.id = id; + this.feeds = feeds.filter(feed => new Feed(feed)); + } +}; \ No newline at end of file