-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplayer.go
411 lines (376 loc) · 16.1 KB
/
player.go
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package opendota
import (
"fmt"
"net/http"
"strconv"
"github.com/dghubble/sling"
)
func newPlayerService(sling *sling.Sling) *PlayerService {
return &PlayerService{
sling: sling.Path("players/"),
}
}
// PlayerService provides methods for accessing information about
// players.
type PlayerService struct {
sling *sling.Sling
}
// PlayerParam is used for customizing Player queries.
type PlayerParam struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
Win int `url:"win,omitempty"`
Patch int `url:"patch,omitempty"`
GameMode int `url:"game_mode,omitempty"`
LobbyType int `url:"lobby_type,omitempty"`
Region int `url:"region,omitempty"`
Date int `url:"date,omitempty"`
LaneRole int `url:"lane_role,omitempty"`
HeroID int `url:"hero_id,omitempty"`
IsRadiant int `url:"is_radiant,omitempty"`
IncAccountID int64 `url:"included_account_id,omitempty"`
ExcAccountID int64 `url:"excluded_account_id,omitempty"`
WithHeroID int `url:"with_hero_id,omitempty"`
AgainstHeroID int `url:"against_hero_id,omitempty"`
Significant int `url:"significant,omitempty"`
Sort string `url:"sort,omitempty"`
Project []string `url:"project,omitempty"`
}
// GameWins represents how many games are won for a player.
type GameWins struct {
Games int `json:"games"`
Win int `json:"win"`
}
// MmrEstimate represents the estimated MMR score for a player.
type MmrEstimate struct {
Estimate int `json:"estimate"`
}
// Player represents stats about a player.
type Player struct {
TrackedUntil string `json:"tracked_until,omitempty"`
SoloCompetitiveRank int `json:"solo_competitive_rank,omitempty"`
MmrEstimate MmrEstimate `json:"mmr_estimate"`
Profile Profile `json:"profile"`
CompetitiveRank int `json:"competitive_rank,omitempty"`
RankTier int `json:"rank_tier"`
}
// PlayerCounts represents the counts of wins for a player for various
// stats.
type PlayerCounts struct {
LeaverStatus map[string]GameWins `json:"leaver_status"`
GameMode map[string]GameWins `json:"game_mode"`
LobbyType map[string]GameWins `json:"lobby_type"`
LaneRole map[string]GameWins `json:"lane_role"`
Region map[string]GameWins `json:"region"`
Patch map[string]GameWins `json:"patch"`
IsRadiant map[string]GameWins `json:"is_radiant"`
}
// PlayerHero represents the stats of a hero played by a player.
type PlayerHero struct {
HeroID string `json:"hero_id"`
LastPlayed int `json:"last_played"`
Games int `json:"games"`
Win int `json:"win"`
WithGames int `json:"with_games"`
WithWin int `json:"with_win"`
AgainstGames int `json:"against_games"`
AgainstWin int `json:"against_win"`
}
// PlayerHistogram represents a distribution of data for a player.
type PlayerHistogram struct {
X int `json:"x"`
Games int `json:"games"`
Win int `json:"win"`
}
// PlayerMatch represents match data for a player.
type PlayerMatch struct {
MatchID int64 `json:"match_id"`
PlayerSlot int `json:"player_slot"`
RadiantWin bool `json:"radiant_win"`
Duration int `json:"duration"`
GameMode int `json:"game_mode"`
LobbyType int `json:"lobby_type"`
HeroID int `json:"hero_id"`
StartTime int `json:"start_time"`
Version int `json:"version"`
Kills int `json:"kills"`
Deaths int `json:"deaths"`
Assists int `json:"assists"`
Skill int `json:"skill,omitempty"`
XpPerMin int `json:"xp_per_min,omitempty"`
GoldPerMin int `json:"gold_per_min,omitempty"`
HeroDamage int `json:"hero_damage,omitempty"`
TowerDamage int `json:"tower_damage,omitempty"`
HeroHealing int `json:"hero_healing,omitempty"`
LastHits int `json:"last_hits,omitempty"`
Lane int `json:"lane,omitempty"`
LaneRole int `json:"lane_role,omitempty"`
IsRoaming bool `json:"is_roaming,omitempty"`
Cluster int `json:"cluster,omitempty"`
LeaverStatus int `json:"leaver_status,omitempty"`
PartySize int `json:"party_size"`
}
// PlayerPeers represents data about peers a player has played with.
type PlayerPeers struct {
AccountID int `json:"account_id"`
LastPlayed int `json:"last_played"`
Win int `json:"win"`
Games int `json:"games"`
WithWin int `json:"with_win"`
WithGames int `json:"with_games"`
AgainstWin int `json:"against_win"`
AgainstGames int `json:"against_games"`
WithGpmSum int `json:"with_gpm_sum"`
WithXpmSum int `json:"with_xpm_sum"`
Personaname string `json:"personaname"`
LastLogin string `json:"last_login"`
Avatar string `json:"avatar"`
AvatarFull string `json:"avatarfull"`
}
// PlayerPros represents data about pro players a player has played with.
type PlayerPros struct {
AccountID int `json:"account_id"`
Name string `json:"name"`
CountryCode string `json:"country_code"`
FantasyRole int `json:"fantasy_role"`
TeamID int `json:"team_id"`
TeamName string `json:"team_name"`
TeamTag string `json:"team_tag"`
IsLocked bool `json:"is_locked"`
IsPro bool `json:"is_pro"`
LockedUntil int `json:"locked_until"`
SteamID string `json:"steamid"`
Avatar string `json:"avatar"`
AvatarMedium string `json:"avatarmedium"`
AvatarFull string `json:"avatarfull"`
ProfileURL string `json:"profileurl"`
Personaname string `json:"personaname"`
Cheese int `json:"cheese"`
FhUnavailable bool `json:"fh_unavailable"`
LocCountryCode string `json:"loccountrycode"`
LastPlayed int `json:"last_played"`
FullHistoryTime string `json:"full_history_time"`
LastMatchTime string `json:"last_match_time"`
Win int `json:"win"`
Games int `json:"games"`
WithWin int `json:"with_win"`
WithGames int `json:"with_games"`
AgainstWin int `json:"against_win"`
AgainstGames int `json:"against_games"`
WithGpmSum int `json:"with_gpm_sum"`
WithXpmSum int `json:"with_xpm_sum"`
}
// PlayerRankings represents the ranking of a player.
type PlayerRankings struct {
HeroID int `json:"hero_id"`
Score float64 `json:"score"`
PercentRank int `json:"percent_rank"`
Card int `json:"card"`
}
// PlayerRatings represents the ratings of a player.
type PlayerRatings struct {
AccountID int `json:"account_id"`
MatchID int64 `json:"match_id"`
SoloCompetitiveRank int `json:"solo_competitive_rank"`
CompetitiveRank int `json:"competitive_rank"`
Time string `json:"time"`
}
// PlayerTotals represents totals in different fields for a player.
type PlayerTotals struct {
Field string `json:"field"`
N int `json:"n"`
Sum int `json:"sum"`
}
// PlayerWardMap represents observer and sentry wards placed by a player.
type PlayerWardMap struct {
Obs map[string]map[string]int `json:"obs"`
Sen map[string]map[string]int `json:"sen"`
}
// PlayerWordCloud represents the words said by a player in chat.
type PlayerWordCloud struct {
MyWordCounts map[string]int `json:"my_word_counts"`
AllWordCounts map[string]int `json:"all_word_counts"`
}
// Profile represents a player's profile.
type Profile struct {
AccountID int `json:"account_id"`
Personaname string `json:"personaname"`
Name string `json:"name"`
Cheese int `json:"cheese"`
SteamID string `json:"steamid"`
Avatar string `json:"avatar"`
AvatarMedium string `json:"avatarmedium"`
AvatarFull string `json:"avatarfull"`
ProfileURL string `json:"profileurl"`
LastLogin string `json:"last_login,omitempty"`
LocCountryCode string `json:"loccountrycode"`
}
// WinLoss represents the totals of wins and losses for a player.
type WinLoss struct {
Win int `json:"win"`
Lose int `json:"lose"`
}
// Counts takes an Account ID and optional params returns the counts
// of categories for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1counts%2Fget
func (s *PlayerService) Counts(accountID int64, params *PlayerParam) (PlayerCounts, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
counts := new(PlayerCounts)
apiError := new(APIError)
path := fmt.Sprintf("%s/counts", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(counts, apiError)
return *counts, resp, relevantError(err, *apiError)
}
// Heroes takes an Account ID and optional params and returns information
// about heroes played by a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1heroes%2Fget
func (s *PlayerService) Heroes(accountID int64, params *PlayerParam) ([]PlayerHero, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
playerheroes := new([]PlayerHero)
apiError := new(APIError)
path := fmt.Sprintf("%s/heroes", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(playerheroes, apiError)
return *playerheroes, resp, relevantError(err, *apiError)
}
// Histograms takes an Account ID, Field and optional params and returns a
// distribution of matches of a player for that field.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1histograms~1%7Bfield%7D%2Fget
func (s *PlayerService) Histograms(accountID int64, field string, params *PlayerParam) ([]PlayerHistogram, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
histograms := new([]PlayerHistogram)
apiError := new(APIError)
path := fmt.Sprintf("%s/histograms/%s", strconv.Itoa(int(accountID)), field)
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(histograms, apiError)
return *histograms, resp, relevantError(err, *apiError)
}
// Matches takes an Account ID and optional params and returns recent matches for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1matches%2Fget
func (s *PlayerService) Matches(accountID int64, params *PlayerParam) ([]PlayerMatch, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
playermatches := new([]PlayerMatch)
apiError := new(APIError)
path := fmt.Sprintf("%s/matches", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(playermatches, apiError)
return *playermatches, resp, relevantError(err, *apiError)
}
// Peers takes an Account ID and optional params and returns information about games
// played with other players.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1peers%2Fget
func (s *PlayerService) Peers(accountID int64, params *PlayerParam) ([]PlayerPeers, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
peers := new([]PlayerPeers)
apiError := new(APIError)
path := fmt.Sprintf("%s/peers", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(peers, apiError)
return *peers, resp, relevantError(err, *apiError)
}
// Player takes an account id and returns information about a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D%2Fget
func (s *PlayerService) Player(accountID int64) (Player, *http.Response, error) {
player := new(Player)
apiError := new(APIError)
path := fmt.Sprintf("%s", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).Receive(player, apiError)
return *player, resp, relevantError(err, *apiError)
}
// Pros takes an Account ID and optional params and returns information about
// games played with other pro players.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1pros%2Fget
func (s *PlayerService) Pros(accountID int64, params *PlayerParam) ([]PlayerPros, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
pros := new([]PlayerPros)
apiError := new(APIError)
path := fmt.Sprintf("%s/pros", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(pros, apiError)
return *pros, resp, relevantError(err, *apiError)
}
// Rankings takes an Account ID and returns ranking history for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1rankings%2Fget
func (s *PlayerService) Rankings(accountID int64) ([]PlayerRankings, *http.Response, error) {
rankings := new([]PlayerRankings)
apiError := new(APIError)
path := fmt.Sprintf("%s/rankings", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).Receive(rankings, apiError)
return *rankings, resp, relevantError(err, *apiError)
}
// Ratings takes an Account ID and returns rating history for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1ratings%2Fget
func (s *PlayerService) Ratings(accountID int64) ([]PlayerRatings, *http.Response, error) {
ratings := new([]PlayerRatings)
apiError := new(APIError)
path := fmt.Sprintf("%s/ratings", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).Receive(ratings, apiError)
return *ratings, resp, relevantError(err, *apiError)
}
// RecentMatches takes an Account ID and returns recent matches for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1recentMatches%2Fget
func (s *PlayerService) RecentMatches(accountID int64) ([]PlayerMatch, *http.Response, error) {
playermatches := new([]PlayerMatch)
apiError := new(APIError)
path := fmt.Sprintf("%s/recentMatches", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).Receive(playermatches, apiError)
return *playermatches, resp, relevantError(err, *apiError)
}
// Totals takes an Account ID and optional params and returns totals for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1totals%2Fget
func (s *PlayerService) Totals(accountID int64, params *PlayerParam) ([]PlayerTotals, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
totals := new([]PlayerTotals)
apiError := new(APIError)
path := fmt.Sprintf("%s/totals", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(totals, apiError)
return *totals, resp, relevantError(err, *apiError)
}
// WardMap takes an Account ID and optional params and returns wards placed
// in matches by a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1wardmap%2Fget
func (s *PlayerService) WardMap(accountID int64, params *PlayerParam) (PlayerWardMap, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
wardmap := new(PlayerWardMap)
apiError := new(APIError)
path := fmt.Sprintf("%s/wardmap", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(wardmap, apiError)
return *wardmap, resp, relevantError(err, *apiError)
}
// WinLoss takes an Account ID and optional params and returns the
// win/loss count for a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1wl%2Fget
func (s *PlayerService) WinLoss(accountID int64, params *PlayerParam) (WinLoss, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
winloss := new(WinLoss)
apiError := new(APIError)
path := fmt.Sprintf("%s/wl", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(winloss, apiError)
return *winloss, resp, relevantError(err, *apiError)
}
// WordCloud takes an Account ID and optional params and returns
// words said in matches by a player.
// https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1wordcloud%2Fget
func (s *PlayerService) WordCloud(accountID int64, params *PlayerParam) (PlayerWordCloud, *http.Response, error) {
if params == nil {
params = &PlayerParam{}
}
wordcloud := new(PlayerWordCloud)
apiError := new(APIError)
path := fmt.Sprintf("%s/wordcloud", strconv.Itoa(int(accountID)))
resp, err := s.sling.New().Get(path).QueryStruct(params).Receive(wordcloud, apiError)
return *wordcloud, resp, relevantError(err, *apiError)
}