Add loading data from json file
This commit is contained in:
parent
372e6f3d74
commit
6a4f2a32d8
23
app/index.js
23
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
|
//acts as on ready function
|
||||||
module.exports = (client) => {
|
module.exports = (client) => {
|
||||||
client.on("message", message => message.reply("Hello!"));
|
const guildsData = FileSystem.existsSync(SAVE_FILE) ? parseJSON(JSONFile.readFileSync(SAVE_FILE)) : {}; //pull saved data from file
|
||||||
//check messages in channel for links posted since last online
|
|
||||||
|
|
||||||
//set up an interval to check all the feeds
|
//set up an interval to check all the feeds
|
||||||
|
|
||||||
//set up an on message handler to detect when links are posted
|
//set up an on message handler to detect when links are posted
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function parseJSON(json) {
|
||||||
|
const guildIDs = Object.keys(json);
|
||||||
|
guildIDs.forEach(guildID => { guildIDs[guildID] = new GuildData(guildIDs[guildID]); });
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
|
const Feed = require("./feed.js");
|
||||||
|
|
||||||
module.exports = class GuildData {
|
module.exports = class GuildData {
|
||||||
constructor({id, feeds}) {
|
constructor({id, feeds}) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.feeds = feeds
|
this.feeds = feeds.filter(feed => new Feed(feed));
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in a new issue