From cad49e6640d6feece07b574b1a6030268936edcf Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 2 Aug 2015 13:13:13 +0200 Subject: [PATCH] added dota-match-history --- client.go | 21 ++++++++++ cmd/steam/commands.go | 13 ++++++ dota.go | 96 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 dota.go diff --git a/client.go b/client.go index 499a817..10ec9a6 100644 --- a/client.go +++ b/client.go @@ -85,6 +85,27 @@ func (c *Client) GetPlayerSummaries(steamids ...uint64) ([]PlayerSummary, error) return response.V.Players, nil } +func (c *Client) DotaMatchHistory() ([]DotaMatch, error) { + url := fmt.Sprintf("https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/v0001/?key=%s", c.key) + var response struct { + V struct { + Status int `json:"status"` + NumResults int `json:"num_results"` + Total int `json:"total_results"` + Remaining int `json:"results_remaining"` + Matches []DotaMatch `json:"matches"` + } `json:"result"` + } + res, err := http.Get(url) + if err != nil { + return nil, errorf(err, "unable to get match history") + } + if err := json.NewDecoder(res.Body).Decode(&response); err != nil { + return nil, errorf(err, "unable to parse match history response") + } + return response.V.Matches, nil +} + /* "name": "ISteamUser", "methods": [ diff --git a/cmd/steam/commands.go b/cmd/steam/commands.go index 9641d5d..5ed37a1 100644 --- a/cmd/steam/commands.go +++ b/cmd/steam/commands.go @@ -73,6 +73,19 @@ func init() { } }, }, + "dota-match-history": command{ + handler: func(c *steam.Client, args ...string) { + matches, err := c.DotaMatchHistory() + if err != nil { + bail(1, "%v", err) + } + w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0) + defer w.Flush() + for _, match := range matches { + fmt.Fprintln(w, match.Oneline()) + } + }, + }, "commands": command{ handler: func(c *steam.Client, args ...string) { keys := make([]string, 0, len(commands)) diff --git a/dota.go b/dota.go new file mode 100644 index 0000000..1b99064 --- /dev/null +++ b/dota.go @@ -0,0 +1,96 @@ +package steam + +import ( + "bytes" + "fmt" +) + +type DotaMatch struct { + Id uint64 `json:"match_id"` + SeqNum uint64 `json:"match_seq_num"` + StartTime uint64 `json:"start_time"` + LobbyType int `json:"lobby_type"` + RadiantTeamId int `json:"radian_team_id"` + DireTeamId int `json:"dire_team_id"` + Players []DotaMatchPlayer `json:"players"` +} + +func (d DotaMatch) Oneline() string { + var buf bytes.Buffer + fmt.Fprintf(&buf, "%d\t%d\t%d\t%d\t%d\t%d\n", d.Id, d.SeqNum, d.StartTime, d.LobbyType, d.RadiantTeamId, d.DireTeamId) + for _, player := range d.Players { + fmt.Fprintf(&buf, "-\t-\t-\t%d\t%d\t%d\n", player.AccountId, player.PlayerSlot, player.HeroId) + } + return buf.String() +} + +type DotaMatchPlayer struct { + AccountId uint64 `json:"account_id"` + PlayerSlot int `json:"player_slot"` + HeroId int `json:"hero_id"` +} + +/* +{ + "match_id": 1680503925, + "match_seq_num": 1497692382, + "start_time": 1438511639, + "lobby_type": 0, + "radiant_team_id": 0, + "dire_team_id": 0, + "players": [ + { + "account_id": 4294967295, + "player_slot": 0, + "hero_id": 61 + }, + { + "account_id": 4294967295, + "player_slot": 1, + "hero_id": 56 + }, + { + "account_id": 4294967295, + "player_slot": 2, + "hero_id": 41 + }, + { + "account_id": 264612072, + "player_slot": 3, + "hero_id": 48 + }, + { + "account_id": 4294967295, + "player_slot": 4, + "hero_id": 95 + }, + { + "account_id": 176784521, + "player_slot": 128, + "hero_id": 99 + }, + { + "account_id": 4294967295, + "player_slot": 129, + "hero_id": 5 + }, + { + "account_id": 4294967295, + "player_slot": 130, + "hero_id": 17 + }, + { + "account_id": 62572906, + "player_slot": 131, + "hero_id": 46 + }, + { + "account_id": 111126659, + "player_slot": 132, + "hero_id": 66 + } + ] + +}, + +*/