diff --git a/lib/BetterDiscord.js b/lib/BetterDiscord.js index 6a1b9571..8f17bac2 100644 --- a/lib/BetterDiscord.js +++ b/lib/BetterDiscord.js @@ -40,19 +40,21 @@ function initStorage() { } else { bdStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdStorage.json")); } - if(!_fs.existsSync(_cfg.dataPath + "/bdPluginStorage.json")) { - bdPluginStorage.data = bdPluginStorage.defaults.data; - _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage, null, 4)); - } else { - bdPluginStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdPluginStorage.json")); - } }; bdStorage.get = function(i, m, pn) { if(m) return bdStorage.data[i] || ""; - if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; - return bdPluginStorage.data[pn][i] || ""; + + if(bdPluginStorage[pn] !== undefined) { + return bdPluginStorage[pn][i] || undefined; + } + + if(_fs.existsSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")) { + bdPluginStorage[pn] = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")); + return bdPluginStorage[pn][i] || undefined; + } + }; bdStorage.set = function(i, v, m, pn) { @@ -60,9 +62,9 @@ bdStorage.set = function(i, v, m, pn) { bdStorage.data[i] = v; _fs.writeFileSync(_cfg.dataPath + "/bdstorage.json", JSON.stringify(bdStorage.data, null, 4)); } else { - if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; - bdPluginStorage.data[pn][i] = v; - _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage.data, null, 4)); + if(bdPluginStorage[pn] === undefined) bdPluginStorage[pn] = {}; + bdPluginStorage[pn][i] = v; + _fs.writeFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json", JSON.stringify(bdPluginStorage[pn], null, 4)); } return true; };