Created
June 3, 2018 16:16
-
-
Save GuimDev/6ff69371c47b3286aa020f8e270ffd1e to your computer and use it in GitHub Desktop.
Script nodejs pour récupérer le ilvl de l'équipe adverse pendant le BG via un script WoW (lua) #L133
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require("https"), | |
fs = require("fs"); | |
const apikey = "yourapikey"; | |
//var str = "Shakaoh-Archimonde;Ardatlili-Archimonde;Ivresse-CultedelaRivenoire;Crollet-Archimonde;Yxzu-Hyjal;Linahot-Dalaran;Alej-Arakarahm;Brrlingo-Medivh;Keyshu-Hyjal;Pyrhan-Archimonde"; | |
const Players = [], | |
waitingList = [], | |
scriptLocale = "en_GB", //"fr_FR"; | |
progressbar = []; | |
const tableRealmName2Slug = (function(file) { | |
if (!fs.existsSync(file)) | |
return false; | |
return JSON.parse(fs.readFileSync(file)); | |
})("./tableRealmName2Slug.json"); | |
function parsePlayersList(str) { | |
const players = str.split(";"); | |
for (let i = 0, Rname, abc; i < players.length; i++) { | |
abc = players[i].split("-"); | |
waitingList.push([abc[0], abc[1]]); | |
} | |
} | |
function waitingSibling() { | |
const player = waitingList[0]; | |
if (!player) | |
return endOfQueue(); | |
getilvl(player[0], player[1]); | |
waitingList.shift(); | |
} | |
function numK(num) { | |
return Math.floor(num / 100) / 10; | |
} | |
function endOfQueue() { | |
let text = ""; | |
Players.sort(function(a, b) { | |
return b.ilvl - a.ilvl; | |
}); | |
console.log(""); | |
for (let i = 0, line, player; i < Players.length; i++) { | |
player = Players[i]; | |
line = (i + 1) + ". " + (player.friend ? "❤" : ""); | |
line += player.name + " i" + player.ilvl + " "; | |
line += "(a:" + numK(player.achievement) + "K k:" + numK(player.kills) + "K)"; | |
console.log(line); | |
text += line + "\n"; | |
} | |
fs.writeFileSync("./score_ilvl.txt", text); | |
print_Xplan(); | |
} | |
function start(strPlayersList) { // "name1-realm;name2-realm;name3-realm;..." | |
if (!strPlayersList) | |
return console.log("Argument manquant."); | |
parsePlayersList(strPlayersList); | |
waitingSibling(); | |
console.log("\x1B[2JWork in progress...\n"); | |
} | |
var lastHeader = null; | |
function print_Xplan() { | |
console.log("\n\n\n"); | |
for (let property in lastHeader) { | |
if (lastHeader.hasOwnProperty(property)) { | |
if (property.indexOf("x-plan") !== -1) { | |
console.log(property, "\t:", lastHeader[property]); | |
if (property === "x-plan-quota-reset") | |
console.log(new Date(lastHeader[property]).toLocaleTimeString()); | |
} | |
} | |
} | |
} | |
function getilvl(name, realm) { | |
const friend = (name[0] === "#") ? true : false; | |
if (friend) { | |
name = name.substr(1); | |
} | |
const slug = (!tableRealmName2Slug[realm]) ? null : tableRealmName2Slug[realm]; | |
const url = "https://eu.api.battle.net/wow/character/" + encodeURI(slug || realm) + "/" + encodeURI(name) + "?fields=items&locale=" + scriptLocale + "&apikey="; | |
const request = https.get(url + apikey, function(response) { | |
var output = ""; | |
response.setEncoding("utf8"); | |
response.on("data", function(chunk) { | |
output += chunk; | |
}); | |
response.on("end", () => { | |
console.log("\x1B[2A\x1B[0J"); | |
if (response.statusCode === 200) { | |
const obj = JSON.parse(output); | |
//console.log(JSON.stringify(obj, null, 4)); | |
Players.push({ | |
name: name + "-" + realm, | |
friend: friend, | |
ilvl: obj.items.averageItemLevel, | |
achievement: obj.achievementPoints, | |
kills: obj.totalHonorableKills | |
}); | |
progressbar.push("+"); | |
} else { | |
console.log("\x1B[1Aerror:", name + "-" + realm, "slug:", slug, "\n"); | |
progressbar.push("¤"); | |
} | |
console.log("[" + progressbar.join("") + new Array(waitingList.length + 1).join("-") + "]"); | |
waitingSibling(); | |
}); | |
lastHeader = response.headers; | |
}); | |
} | |
start(process.argv[2]); | |
/*function bgPlayers() | |
local playernumbers = GetNumBattlefieldScores() | |
local strP = ""; | |
for i = 1, playernumbers do | |
local name,_,_,_,_,faction,_,_,class,_ ,_,_,_,_,_,spec = GetBattlefieldScore(i) | |
if faction == 0 then | |
if string.find(name, "-") == nil then | |
name = name .. "-" .. GetRealmName() | |
end | |
if strP ~= "" then | |
strP = strP .. ";" | |
end | |
strP = strP .. name | |
end | |
end | |
return strP | |
end | |
ChatFrame1EditBox:SetText('"'..bgPlayers()..'"')*/ | |
function getRealmName(callback) { | |
tableRealmName2Slug = {}; | |
const locales = ["en_GB", "de_DE", "es_ES", "fr_FR", "it_IT", "pl_PL", "pt_PT", "ru_RU"]; | |
var loopAsync = function(i) { | |
const locale = locales[i]; | |
const url = "https://eu.api.battle.net/wow/realm/status?locale=" + locale + "&apikey="; | |
const request = https.get(url + apikey, function(response) { | |
var output = ""; | |
response.setEncoding("utf8"); | |
response.on("data", function(chunk) { | |
output += chunk; | |
}); | |
response.on("end", () => { | |
if (response.statusCode === 200) { | |
const obj = JSON.parse(output); | |
if (!obj.realms) | |
return; | |
for (let i = 0, realm; i < obj.realms.length; i++) { | |
realm = obj.realms[i]; | |
if (realm.name.toLowerCase() === realm.slug) | |
continue; | |
if (tableRealmName2Slug[realm.name.replace(/ /g, "")] && tableRealmName2Slug[realm.name.replace(/ /g, "")] !== realm.slug) { | |
console.log(realm.name.replace(/ /g, ""), tableRealmName2Slug[realm.name.replace(/ /g, "")], realm.slug); | |
} | |
//tableRealmName2Slug[realm.name] = realm.slug; | |
//if (realm.name.match(/ /g)) | |
tableRealmName2Slug[realm.name.replace(/ /g, "")] = realm.slug; | |
} | |
console.log(locale); | |
if (i < locales.length) { | |
loopAsync(i + 1); | |
} else { | |
let json = JSON.stringify(tableRealmName2Slug, null, 4); | |
try { | |
fs.writeFileSync("./tableRealmName2Slug.json", json); | |
} catch (e) { | |
console.log("Erreur.", e, json); | |
} | |
if (typeof callback === "function") | |
callback(); | |
} | |
} | |
}); | |
}); | |
}; | |
loopAsync(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Arguments :
node main Shakaoh-Archimonde;Ardatlili-Archimonde;Ivresse-CultedelaRivenoire;Crollet-Archimonde;Yxzu-Hyjal;Linahot-Dalaran;Alej-Arakarahm;Brrlingo-Medivh;Keyshu-Hyjal;Pyrhan-Archimonde
Retour :