-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendou.js
71 lines (59 loc) · 2.23 KB
/
sendou.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const axios = require('axios');
let getPlayerData = async (playerID) => {
return new Promise(async (resolve, reject) => {
let res = await axios.get(`https://sendou.ink/_next/data/wBYebeJrpEqf5w-7mCZ1G/u/${playerID}.json`).catch(e => {
return reject(e);
})
if (res && res.data) {
return resolve(res.data);
}
else {
return reject("There was an unkown error.")
}
});
}
exports.getFullDataFromTeam = async (team) => {
return new Promise(async (resolve, reject) => {
let data = {};
let res = await axios.get("https://sendou.ink/_next/data/wBYebeJrpEqf5w-7mCZ1G/t.json").catch(null);
if (res && res.data) res = res.data;
else return data;
let query;
let type;
if (team.sendouLink) {
query = team.sendouLink;
type = ['nameForUrl'];
}
else {
query = team.displayName;
type = ['name'];
}
res.pageProps.teams.forEach((team) => {
if (team[type].toLowerCase() === query.toLowerCase()) return data['teamData'] = team;
})
if (data.teamData && data.teamData.roster) {
if (data.teamData.roster.size < 1) return;
else {
let players = [];
let promises = [];
data.teamData.roster.forEach((player) => {
promises.push(getPlayerData(player.id));
})
await Promise.all(promises).then((values) => {
values.forEach((pres) => {
if (pres && !pres.notFound) {
let pdata = pres.pageProps.user;
if (pres.pageProps.peakXPowers) pdata.peakXPowers = pres.pageProps.peakXPowers;
if (pres.pageProps.peakLeaguePowers) pdata.peakLeaguePowers = pres.pageProps.peakLeaguePowers;
players.push(pres.pageProps.user);
}
})
}).catch(e => {
return reject(e);
})
data['players'] = players;
}
}
return resolve(data);
});
}