-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsaveandload.js
More file actions
47 lines (40 loc) · 1.09 KB
/
saveandload.js
File metadata and controls
47 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs');
module.exports = class Main{
//initializes user
init(user, data){ }
//helperCommand
help(){
return {};
}
//returns true iff it processes a command. This will process anything directly involving money.
processMessage(msg, command, usersData){ }
save(user, data){
if(!fs.existsSync("./data")){
fs.mkdirSync("./data");
}
if(!fs.existsSync("./data/" + user.id)){
fs.mkdirSync("./data/" + user.id);
}
fs.writeFileSync("./data/" + user.id + "/data.json", JSON.stringify(data), function(err){ console.log(err)});
}
load(loadFunc){
let data = {};
let folders = fs.readdirSync("./data");
folders.forEach(function(i){
if(i === "globalData.json"){
return;
}
data[i] = JSON.parse(fs.readFileSync("./data/" + i + "/data.json").toString());
});
loadFunc(data);
}
saveGlobalData(data){
if(!fs.existsSync("./data")){
fs.mkdirSync("./data");
}
fs.writeFileSync("./data/globalData.json", JSON.stringify(data), function(err){ });
}
loadGlobalData(loadFunc){
loadFunc(JSON.parse(fs.readFileSync("./data/globalData.json").toString()));
}
}