diff options
-rw-r--r-- | featureClass/featureManager.js | 35 | ||||
-rw-r--r-- | features/events/index.js | 8 | ||||
-rw-r--r-- | features/hud/index.js | 7 | ||||
-rw-r--r-- | utils/networkUtils.js | 62 |
4 files changed, 76 insertions, 36 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index 934feca..8b5a023 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -71,28 +71,25 @@ class FeatureManager { this.featureSettingsData = {} - new Thread(()=>{ - - try{ - if(fetch("http://soopymc.my.to/api/soopyv2/ping").responseCode() >= 400){ - ChatLib.chat(this.messagePrefix + "&cError: Could not connect to Soopy's server. This may cause issues with features breaking but will (hopefully) be back soon.") - } - }catch(e){ + let fetchD = fetch("http://soopymc.my.to/api/soopyv2/ping").async(d=>{ + if(fetchD.responseCode() >= 400 || fetchD.responseCode() === -1){ ChatLib.chat(this.messagePrefix + "&cError: Could not connect to Soopy's server. This may cause issues with features breaking but will (hopefully) be back soon.") } - - this.loadFeatureMetas() - - this.loadFeatureSettings() - Object.keys(this.featureMetas).forEach((feature)=>{ - if(this.featureSettingsData[feature] && this.featureSettingsData[feature].enabled){ - this.loadFeature(feature) - } - }) - - this.finishedLoading = true - }).start() + new Thread(()=>{ + this.loadFeatureMetas() + + this.loadFeatureSettings() + + Object.keys(this.featureMetas).forEach((feature)=>{ + if(this.featureSettingsData[feature] && this.featureSettingsData[feature].enabled){ + this.loadFeature(feature) + } + }) + + this.finishedLoading = true + }).start() + }, true) this.registerStep(false, 30, ()=>{ if(this.featureSettingsDataLastUpdated){ diff --git a/features/events/index.js b/features/events/index.js index 58c408b..7ce40c8 100644 --- a/features/events/index.js +++ b/features/events/index.js @@ -152,7 +152,7 @@ class Events extends Feature { if(!this.showingWaypoints && showingWaypointsNew){ this.loadApi() - }else{ + }else if(showingWaypointsNew){ if(Date.now()-this.nextUpdateApprox > 0 && this.nextUpdateApprox > 0 && Date.now()-this.lastRequest>5000){ this.nextUpdateApprox = -2 this.loadApi() @@ -264,8 +264,10 @@ class Events extends Feature { }) this.burrialData.locations = newLocs - this.sortBurrialLocations() - this.updateBurrialPath() + if(this.showingWaypoints){ + this.sortBurrialLocations() + this.updateBurrialPath() + } } diff --git a/features/hud/index.js b/features/hud/index.js index 917a2f6..41aa953 100644 --- a/features/hud/index.js +++ b/features/hud/index.js @@ -216,7 +216,8 @@ class Hud extends Feature { this.registerEvent("worldLoad", this.worldLoad) this.petLevels = {} - this.petText = "" + this.petText = "&6Pet&7> &fLoading..." + this.petElement.setText(this.petText) this.registerChat("&cAutopet &eequipped your ${pet}&e! &a&lVIEW RULE&r", (pet)=>{ this.petElement.setText("&6Pet&7> "+pet) this.petText = "&6Pet&7> "+pet @@ -515,7 +516,7 @@ class Hud extends Feature { let song = parts[parts.length-1].substr(0,parts[parts.length-1].length-1) if(song === "N/A") continue - if(song === "Spotify Free"||song === "AngleHiddenWindow"){ + if(song === "Spotify Free"||song === "Spotify Premium"||song === "AngleHiddenWindow"){ currentSong = "&cPaused" }else{ if(song === "Spotify") song = "Advertisement" @@ -531,7 +532,7 @@ class Hud extends Feature { updateHudThingos(){ let insb = this.FeatureManager.features["dataLoader"].class.isInSkyblock - if(Date.now()-this.lastUpdatedStatData > 5*60000 && this.hudStat[0].enabled.getValue() && (insb || this.hudStat.map(a=>a.onlySb.getValue()).includes(false))){ + if(Date.now()-this.lastUpdatedStatData > 5*60000 && this.hudStat[0].enabled.getValue() && (!this.lastStatData || insb || this.hudStat.map(a=>(!a.enabled.getValue() || a.onlySb.getValue())).includes(false))){ this.FeatureManager.features["dataLoader"].class.loadApiData("skyblock", false) diff --git a/utils/networkUtils.js b/utils/networkUtils.js index 2f84128..46ac47b 100644 --- a/utils/networkUtils.js +++ b/utils/networkUtils.js @@ -11,6 +11,10 @@ if(!global.networkUtilsThingSoopy){ if(global.soopyv2loggerthing){ global.soopyv2loggerthing.logMessage("Loading API: " + theUrl, 4) } + + // if(theUrl.includes("soopymc.my.to")){ + // throw new Error("Testing to ensure the module works when my server is down") + // } let conn = new jURL(theUrl).openConnection() conn.setRequestProperty("User-Agent", userAgent) @@ -44,20 +48,26 @@ if(!global.networkUtilsThingSoopy){ let loadedConnection = undefined let loadedString = undefined let loadedJSON = undefined + let errorData = undefined let ret = { sync(){ if(loadedString === undefined){ options.includeConnection = true - let data = getUrlContent(url, options) - loadedString = data.stringData - loadedConnection = data.connection + try{ + let data = getUrlContent(url, options) + loadedString = data.stringData + loadedConnection = data.connection + }catch(e){ + errorData = e + loadedString = null + } } - return + return ret }, - async(callback){ + async(callback, _ifError=false){ if(!callback){ callback = ()=>{} } @@ -71,12 +81,21 @@ if(!global.networkUtilsThingSoopy){ loadedConnection = data.connection callback() }, + errcallback: (e)=>{ + loadedString = null + errorData = e + if(_ifError){ + callback() + } + }, url: url, options: options }) }else{ callback() } + + return ret }, text: (callback)=>{ if(!callback){ @@ -88,6 +107,8 @@ if(!global.networkUtilsThingSoopy){ ret.async(()=>{ callback(loadedString) }) + + return ret }, json: (callback)=>{ if(!callback){ @@ -105,17 +126,36 @@ if(!global.networkUtilsThingSoopy){ callback(JSON.parse(data)) }catch(e){} }) + + return ret }, responseCode: (callback)=>{ if(!callback){ ret.sync() - return loadedConnection.getResponseCode() + return loadedConnection?.getResponseCode() || -1 } ret.async(data=>{ - callback(loadedConnection.getResponseCode()) + callback(loadedConnection?.getResponseCode() || -1) }) + + return ret + }, + error: (callback)=>{ + if(!callback){ + ret.sync() + + return errorData + } + + ret.async(data=>{ + if(errorData){ + callback(errorData) + } + }, true) + + return ret } } return ret @@ -128,14 +168,14 @@ if(!global.networkUtilsThingSoopy){ new Thread(()=>{ while(running){ while(pendingRequests.length > 0){ - try{ - let req = pendingRequests.shift() + let req = pendingRequests.shift() + try{ let data = getUrlContent(req.url, req.options) pendingResolves.push([req.callback, data]) }catch(e){ - console.log(e, undefined, true) + pendingResolves.push([req.errcallback, e]) } } Thread.sleep(100) @@ -154,7 +194,7 @@ if(!global.networkUtilsThingSoopy){ callback(data) } }catch(e){ - console.log(e, undefined, true) + console.log(JSON.stringify(e, undefined, 2)) } }) |