globalize_all_functions global string pulsePrefix void function pulsePrefixSet() //Sets our prefix { pulsePrefix = format("\x1b[38;2;%i;%i;%im[PULSE]\x1b[0m", 255, 178, 102) } void function pulsePrintt(string content) //Prints whatever we want printed with given prefix (by standard [PULSE]). { printt(format("%s " + content, pulsePrefix)) } bool function pulseRequestData(string givenURL, table parameterTable, string tablepath) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing. { table > requestTable void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (parameterTable, requestTable, tablepath) { table DecodedJSON = DecodeJSON(response.body) if ("map" in parameterTable) { table map map[expect string(parameterTable["map"])] <- DecodedJSON pulsePrintt(tablepath) pulseData[tablepath] <- map } else { pulseData[tablepath] <- DecodedJSON } } void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) { pulsePrintt("Something went wrong while getting data.") } foreach (key, value in parameterTable) { requestTable[string(key)] <- [expect string(parameterTable[string(key)])] } return NSHttpGet(givenURL, requestTable, onSuccess, onFailure) } int function pulseParse(string parameter, string key, string value, string opt = "none") { if (key == "maps") { parameter = parameter.slice(3) } if (key in pulseData) { table keyandvalTable = expect table(pulseData[key]) if (parameter in keyandvalTable) { table valTable = expect table(keyandvalTable[parameter]) if (opt == "none") { return expect int(valTable[value]) } else { table actualValTable = expect table(valTable[value]) return expect int(actualValTable[opt]) } } } return 0 }