added dota-match-history

master
Jordan Orelli 9 years ago
parent bd963f87af
commit cad49e6640

@ -85,6 +85,27 @@ func (c *Client) GetPlayerSummaries(steamids ...uint64) ([]PlayerSummary, error)
return response.V.Players, nil 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", "name": "ISteamUser",
"methods": [ "methods": [

@ -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{ "commands": command{
handler: func(c *steam.Client, args ...string) { handler: func(c *steam.Client, args ...string) {
keys := make([]string, 0, len(commands)) keys := make([]string, 0, len(commands))

@ -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
}
]
},
*/
Loading…
Cancel
Save