update some files
This commit is contained in:
parent
af3124b8b2
commit
089741a05d
|
@ -11,7 +11,7 @@
|
|||
var _fs = require("fs");
|
||||
var _vm = require("vm")
|
||||
var _config = require("./config.json");
|
||||
var _utils = require("./utils");
|
||||
var _utils = require("./Utils");
|
||||
var _utils2;
|
||||
var _bdIpc = require('electron').ipcMain;
|
||||
var _error = false;
|
||||
|
@ -35,6 +35,10 @@ bdPluginStorage.defaults = {
|
|||
};
|
||||
|
||||
function initStorage() {
|
||||
if (_fs.existsSync(_cfg.dataPath + "/bdStorage.json")) {
|
||||
_fs.renameSync(_cfg.dataPath + "/bdStorage.json", _cfg.dataPath + "/bdstorage.json");
|
||||
}
|
||||
|
||||
if(!_fs.existsSync(_cfg.dataPath + "/bdstorage.json")) {
|
||||
bdStorage.data = bdStorage.defaults.data;
|
||||
_fs.writeFileSync(_cfg.dataPath + "/bdstorage.json", JSON.stringify(bdStorage, null, 4));
|
||||
|
@ -46,13 +50,13 @@ function initStorage() {
|
|||
|
||||
bdStorage.get = function(i, m, pn) {
|
||||
|
||||
if(m) return bdStorage.data[i] || "";
|
||||
if (m) return bdStorage.data[i] || "";
|
||||
|
||||
if(bdPluginStorage[pn] !== undefined) {
|
||||
if (bdPluginStorage[pn] !== undefined) {
|
||||
return bdPluginStorage[pn][i] || undefined;
|
||||
}
|
||||
|
||||
if(_fs.existsSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")) {
|
||||
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;
|
||||
}
|
||||
|
@ -88,7 +92,8 @@ function BetterDiscord(mainWindow) {
|
|||
function createAndCheckData() {
|
||||
getUtils().log("Checking data/cache");
|
||||
|
||||
_cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : '/var/local') + '/BetterDiscord/';
|
||||
let linuxPath = process.env.XDG_CONFIG_HOME ? process.env.XDG_CONFIG_HOME : process.env.HOME + '/.config';
|
||||
_cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : linuxPath) + '/BetterDiscord/';
|
||||
_cfg.userFile = _cfg.dataPath + 'user.json';
|
||||
|
||||
try {
|
||||
|
@ -231,138 +236,9 @@ function updateExtData() {
|
|||
'domain': _cfg.updater.CDN,
|
||||
'url': '//' + _cfg.updater.CDN + '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/js/main.min.js',
|
||||
'localurl': _cfg.localServer + '/BetterDiscordApp/js/main.js?v=1.1',
|
||||
'message': 'load-emoteData-twitchGlobal',
|
||||
'message': 'start-bd',
|
||||
'cacheable': false,
|
||||
'variable': null
|
||||
},
|
||||
'load-publicServers': {
|
||||
'type': 'json',
|
||||
'resource': 'Public Servers',
|
||||
'domain': _cfg.updater.CDN,
|
||||
'url': '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/data/serverlist.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-twitchGlobal',
|
||||
'cacheable': false,
|
||||
'variable': 'publicServers'
|
||||
},
|
||||
'load-emoteData-twitchGlobal': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'Twitch Global Emotedata',
|
||||
'domain': 'twitchemotes.com',
|
||||
'url': '/api_cache/v3/global.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-twitchSub',
|
||||
'cacheable': true,
|
||||
'variable': 'emotesTwitch',
|
||||
'localpath': _cfg.dataPath + "/emotes_twitch_global.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': false,
|
||||
'specialparser': 0,
|
||||
'fallback': 'load-emoteData-twitchGlobal-fallback',
|
||||
'self': 'load-emoteData-twitchGlobal'
|
||||
},
|
||||
'load-emoteData-twitchGlobal-fallback': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'Twitch Global Emotedata',
|
||||
'domain': _cfg.updater.CDN,
|
||||
'url': '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/data/emotedata_twitch_global.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-twitchSub',
|
||||
'cacheable': true,
|
||||
'variable': 'emotesTwitch',
|
||||
'localpath': _cfg.dataPath + "/emotes_twitch_global.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': false,
|
||||
'specialparser': 0,
|
||||
'fallback': 'load-emoteData-twitchSub',
|
||||
'self': 'load-emoteData-twitchGlobal-fallback'
|
||||
},
|
||||
'load-emoteData-twitchSub': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'Twitch Subscriber Emotedata',
|
||||
'domain': 'twitchemotes.com',
|
||||
'url': '/api_cache/v3/subscriber.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-ffz',
|
||||
'cacheable': true,
|
||||
'variable': 'subEmotesTwitch',
|
||||
'localpath': _cfg.dataPath + "/emotes_twitch_subscriber.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': true,
|
||||
'specialparser': 1,
|
||||
'fallback': 'load-emoteData-twitchSub-fallback',
|
||||
'self': 'load-emoteData-twitchSub'
|
||||
},
|
||||
'load-emoteData-twitchSub-fallback': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'Twitch Subscriber Emotedata',
|
||||
'domain': _cfg.updater.CDN,
|
||||
'url': '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/data/emotedata_twitch_subscriber.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-ffz',
|
||||
'cacheable': true,
|
||||
'variable': 'subEmotesTwitch',
|
||||
'localpath': _cfg.dataPath + "/emotes_twitch_subscriber.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': true,
|
||||
'specialparser': 1,
|
||||
'fallback': 'load-emoteData-ffz',
|
||||
'self': 'load-emoteData-twitchSub-fallback'
|
||||
},
|
||||
'load-emoteData-ffz': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'FrankerFaceZ Emotedata',
|
||||
'domain': _cfg.updater.CDN,
|
||||
'url': '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/data/emotedata_ffz.json',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-bttv',
|
||||
'cacheable': true,
|
||||
'variable': 'emotesFfz',
|
||||
'localpath': _cfg.dataPath + "/emotes_ffz.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': true,
|
||||
'specialparser': 2,
|
||||
'fallback': 'load-emoteData-bttv',
|
||||
'self': 'load-emoteData-ffz'
|
||||
},
|
||||
'load-emoteData-bttv': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'BTTV Emotedata',
|
||||
'domain': 'api.betterttv.net',
|
||||
'url': '/emotes',
|
||||
'localurl': null,
|
||||
'message': 'load-emoteData-bttv-2',
|
||||
'cacheable': true,
|
||||
'variable': 'emotesBTTV',
|
||||
'localpath': _cfg.dataPath + "/emotes_bttv.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': false,
|
||||
'specialparser': 3,
|
||||
'fallback': 'load-emoteData-bttv-2',
|
||||
'self': 'load-emoteData-bttv'
|
||||
},
|
||||
'load-emoteData-bttv-2': {
|
||||
'type': 'emotedata',
|
||||
'resource': 'BTTV Emotedata',
|
||||
'domain': _cfg.updater.CDN,
|
||||
'url': '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/data/emotedata_bttv.json',
|
||||
'localurl': null,
|
||||
'message': 'start-bd',
|
||||
'cacheable': true,
|
||||
'variable': 'emotesBTTV2',
|
||||
'localpath': _cfg.dataPath + "/emotes_bttv_2.json",
|
||||
'encoding': "utf8",
|
||||
'https': true,
|
||||
'parse': false,
|
||||
'specialparser': 4,
|
||||
'fallback': 'start-bd',
|
||||
'self': 'load-emoteData-bttv-2'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -453,7 +329,7 @@ function loadPlugins() {
|
|||
getUtils().injectVarRaw("bdpluginErrors", "[]");
|
||||
|
||||
files.forEach(function(fileName) {
|
||||
if (!_fs.lstatSync(pluginPath + fileName).isFile() || fileName.endsWith(".config.json")) return;
|
||||
if (!_fs.statSync(pluginPath + fileName).isFile() || fileName.endsWith(".config.json")) return;
|
||||
if(!fileName.endsWith(".plugin.js")) {
|
||||
getUtils().log("Invalid plugin detected: " + fileName);
|
||||
return;
|
||||
|
@ -570,7 +446,7 @@ function loadThemes() {
|
|||
getUtils().injectVarRaw("bdthemes", "{}");
|
||||
|
||||
files.forEach(function(fileName) {
|
||||
if (!_fs.lstatSync(themePath + fileName).isFile()) return;
|
||||
if (!_fs.statSync(themePath + fileName).isFile()) return;
|
||||
if(!fileName.endsWith(".theme.css")) {
|
||||
getUtils().log("Invalid theme detected " + fileName);
|
||||
return;
|
||||
|
@ -705,7 +581,7 @@ function ipcAsyncMessage(event, arg) {
|
|||
|
||||
if(arg == "start-bd") {
|
||||
getUtils().log("Starting Up", 100, 100);
|
||||
getUtils().execJs('var mainCore; var startBda = function() { mainCore = new Core(); mainCore.init(); }; startBda();');
|
||||
getUtils().execJs(`var mainCore; var startBda = function() { mainCore = new Core(${JSON.stringify(_cfg)}); mainCore.init(); }; startBda();`);
|
||||
getUtils().saveLogs(_cfg.dataPath);
|
||||
}
|
||||
}
|
||||
|
@ -723,76 +599,25 @@ function loadExtData(extData) {
|
|||
switch(extData.type) {
|
||||
case 'javascript':
|
||||
getUtils().injectJavaScriptSync(url, extData.message);
|
||||
break;
|
||||
break;
|
||||
case 'css':
|
||||
getUtils().injectStylesheetSync(url, extData.message);
|
||||
break;
|
||||
break;
|
||||
case 'json':
|
||||
getUtils().download(extData.domain, extData.url, function(data) {
|
||||
getUtils().injectVar(extData.variable, data);
|
||||
getUtils().sendIcpAsync(extData.message);
|
||||
});
|
||||
break;
|
||||
case 'emotedata':
|
||||
if(extData.variable != "emotesTwitch") {
|
||||
getUtils().injectVarRaw(extData.variable, "{}");
|
||||
}
|
||||
var exists = _fs.existsSync(extData.localpath);
|
||||
if(exists && !_cfg.cache.expired && extData.cacheable) {
|
||||
loadEmoteData(extData, true);
|
||||
} else {
|
||||
loadEmoteData(extData, false);
|
||||
}
|
||||
break;
|
||||
getUtils().download(extData.domain, extData.url, function(data) {
|
||||
getUtils().injectVar(extData.variable, data);
|
||||
getUtils().sendIcpAsync(extData.message);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}catch(err) {
|
||||
}
|
||||
catch(err) {
|
||||
getUtils().warn(err);
|
||||
getUtils().alert("Something went wrong :( Attempting to run.", err);
|
||||
getUtils().sendIcpAsync(extData.message);
|
||||
}
|
||||
}
|
||||
|
||||
function loadEmoteData(extData, local) {
|
||||
//getUtils().log(extData.self);
|
||||
if(local) {
|
||||
getUtils().log("Reading " + extData.resource + " from file");
|
||||
var data = _fs.readFileSync(extData.localpath, extData.encoding);
|
||||
|
||||
if(testJSON(extData, data)) {
|
||||
injectEmoteData(extData, data);
|
||||
} else {
|
||||
getUtils().log("Deleting cached file " + extData.resource);
|
||||
_fs.unlinkSync(extData.localpath);
|
||||
getUtils().sendIcpAsync(extData.self);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(extData.https) {
|
||||
getUtils().download(extData.domain, extData.url, function(data) {
|
||||
var parsedEmoteData = parseEmoteData(extData, data);
|
||||
|
||||
if(parsedEmoteData == null) {
|
||||
getUtils().sendIcpAsync(extData.fallback);
|
||||
return true;
|
||||
}
|
||||
saveEmoteData(extData, parsedEmoteData);
|
||||
injectEmoteData(extData, parsedEmoteData);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
getUtils().downloadHttp(extData.url, function(data) {
|
||||
var parsedEmoteData = parseEmoteData(extData, data);
|
||||
if(parsedEmoteData == null) {
|
||||
getUtils().sendIcpAsync(extData.fallback);
|
||||
return true;
|
||||
}
|
||||
saveEmoteData(extData, parsedEmoteData);
|
||||
injectEmoteData(extData, parsedEmoteData);
|
||||
});
|
||||
}
|
||||
|
||||
function testJSON(extData, data) {
|
||||
getUtils().log("Validating " + extData.resource);
|
||||
try {
|
||||
|
@ -806,98 +631,6 @@ function testJSON(extData, data) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function injectEmoteData(extData, data) {
|
||||
if(data == null) {
|
||||
getUtils().sendIcpAsync(extData.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if(data.parse) {
|
||||
getUtils().injectVarRaw(extData.variable, 'JSON.parse(\'' + data + '\');');
|
||||
} else {
|
||||
getUtils().injectVarRaw(extData.variable, data);
|
||||
}
|
||||
|
||||
getUtils().sendIcpAsync(extData.message);
|
||||
}
|
||||
|
||||
function saveEmoteData(extData, data) {
|
||||
try {
|
||||
getUtils().log("Saving resource to file " + extData.resource);
|
||||
_fs.writeFileSync(extData.localpath, data, extData.encoding);
|
||||
} catch(err) {
|
||||
getUtils().err("Failed to save resource to file " + extData.resource);
|
||||
}
|
||||
}
|
||||
|
||||
function parseEmoteData(extData, data) {
|
||||
getUtils().log("Parsing: " + extData.resource);
|
||||
|
||||
var returnData;
|
||||
|
||||
switch(extData.specialparser) {
|
||||
case 0: //Twitch Global Emotes
|
||||
return data;
|
||||
break;
|
||||
case 1: //Twitch Subscriber Emotes
|
||||
returnData = {};
|
||||
if(!testJSON(extData, data) || !data || !Object.keys(data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
data = JSON.parse(data);
|
||||
|
||||
/*var channels = data;
|
||||
for(var channel in channels) {
|
||||
var emotes = channels[channel]["emotes"];
|
||||
for(var i = 0 ; i < emotes.length ; i++) {
|
||||
var code = emotes[i]["code"];
|
||||
var id = emotes[i]["id"];
|
||||
returnData[code] = id;
|
||||
}
|
||||
}
|
||||
|
||||
returnData = JSON.stringify(returnData);*/
|
||||
|
||||
var keys = Object.keys(data);
|
||||
if (!keys) return null;
|
||||
keys.forEach(key => {
|
||||
var emotes = data[key].emotes;
|
||||
emotes.forEach(emote => {
|
||||
returnData[emote.code] = emote.id;
|
||||
});
|
||||
});
|
||||
returnData = JSON.stringify(returnData);
|
||||
break;
|
||||
case 2: //FFZ Emotes
|
||||
returnData = data;
|
||||
break;
|
||||
case 3: //BTTV Emotes
|
||||
returnData = {};
|
||||
|
||||
if(!testJSON(extData, data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
data = JSON.parse(data);
|
||||
|
||||
for(var emote in data.emotes) {
|
||||
emote = data.emotes[emote];
|
||||
var url = emote.url;
|
||||
var code = emote.regex;
|
||||
|
||||
returnData[code] = url;
|
||||
}
|
||||
|
||||
returnData = JSON.stringify(returnData);
|
||||
break;
|
||||
case 4:
|
||||
returnData = data;
|
||||
break;
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
|
||||
function getUtils() {
|
||||
return _utils2;
|
||||
}
|
||||
|
|
|
@ -94,9 +94,6 @@ Utils.prototype.jsLog = function(message, type) {
|
|||
|
||||
Utils.prototype.updateLoading = function(message, cur, max) {
|
||||
this.log(message);
|
||||
this.execJs('document.getElementById("bd-status").innerHTML = "BetterDiscord - '+message+' : ";');
|
||||
this.execJs('document.getElementById("bd-pbar").value = '+cur+';');
|
||||
this.execJs('document.getElementById("bd-pbar").max = '+max+';');
|
||||
}
|
||||
|
||||
//Logger
|
||||
|
@ -274,6 +271,9 @@ Utils.prototype.openDir = function(path) {
|
|||
case "darwin":
|
||||
require("child_process").exec('open ' + path);
|
||||
break;
|
||||
default:
|
||||
require("child_process").exec('xdg-open ' + path);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue