This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (94 loc) · 2.43 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* hotslogs
* https://github.com/Nonemoticoner/hotslogs
*
* Copyright (c) 2016 Nonemoticoner
* Licensed under the MIT license.
*/
var request = require('request');
module.exports = {
// get unique ID (integer) that is assigned to player in HOTS Logs
getID: function (battletag, region, callback) {
var name = battletag.replace('#', '_').trim(),
region_no = 0;
switch(region){
case "US":
region_no = 1;
break;
case "EU":
region_no = 2;
break;
case "KR":
region_no = 3;
break;
case "CN":
region_no = 5;
break;
}
var address = 'https://www.hotslogs.com/API/Players/' + region_no.toString() + '/' + name;
request(address, function (error, response, body) {
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
if(data != null && typeof data.PlayerID == "number"){
callback(data.PlayerID);
}
else{
callback(null);
}
}
else{
throw error;
}
});
},
// get basic data about player
getData: function (id, callback) {
var address = 'https://www.hotslogs.com/API/Players/' + id.toString();
request(address, function (error, response, body) {
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
if(data != null){
var player = {};
player.id = data.PlayerID;
player.name = data.Name;
player.rankings = {};
player.rankings.quickMatch = {
MMR: null,
rank: null
};
player.rankings.heroLeague = {
MMR: null,
rank: null
};
player.rankings.teamLeague = {
MMR: null,
rank: null
};
for (var i = data.LeaderboardRankings.length - 1; i >= 0; i--) {
switch(data.LeaderboardRankings[i].GameMode){
case "QuickMatch":
player.rankings.quickMatch.MMR = data.LeaderboardRankings[i].CurrentMMR;
player.rankings.quickMatch.rank = data.LeaderboardRankings[i].LeagueRank;
break;
case "HeroLeague":
player.rankings.heroLeague.MMR = data.LeaderboardRankings[i].CurrentMMR;
player.rankings.heroLeague.rank = data.LeaderboardRankings[i].LeagueRank;
break;
case "TeamLeague":
player.rankings.teamLeague.MMR = data.LeaderboardRankings[i].CurrentMMR;
player.rankings.teamLeague.rank = data.LeaderboardRankings[i].LeagueRank;
break;
}
}
callback(player);
}
else{
callback(null);
}
}
else{
throw error;
}
});
}
};