match details

master
Jordan Orelli 10 years ago
parent cad49e6640
commit 482b77f766

@ -106,6 +106,21 @@ func (c *Client) DotaMatchHistory() ([]DotaMatch, error) {
return response.V.Matches, nil return response.V.Matches, nil
} }
func (c *Client) DotaMatchDetails(id uint64) (*DotaMatchDetails, error) {
url := fmt.Sprintf("https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/v0001/?key=%s&match_id=%d", c.key, id)
res, err := http.Get(url)
if err != nil {
return nil, errorf(err, "unable to get match details")
}
var result struct {
V DotaMatchDetails `json:"result"`
}
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
return nil, errorf(err, "unable to parse match details")
}
return &result.V, nil
}
/* /*
"name": "ISteamUser", "name": "ISteamUser",
"methods": [ "methods": [

@ -86,6 +86,22 @@ func init() {
} }
}, },
}, },
"dota-match-details": command{
handler: func(c *steam.Client, args ...string) {
if len(args) != 1 {
bail(1, "please provide exactly one match id")
}
id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
bail(1, "bad match id: %s", err)
}
details, err := c.DotaMatchDetails(id)
if err != nil {
bail(1, "%v", err)
}
details.Display(os.Stdout)
},
},
"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))

@ -3,6 +3,8 @@ package steam
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"strings"
) )
type DotaMatch struct { type DotaMatch struct {
@ -21,7 +23,7 @@ func (d DotaMatch) Oneline() string {
for _, player := range d.Players { for _, player := range d.Players {
fmt.Fprintf(&buf, "-\t-\t-\t%d\t%d\t%d\n", player.AccountId, player.PlayerSlot, player.HeroId) fmt.Fprintf(&buf, "-\t-\t-\t%d\t%d\t%d\n", player.AccountId, player.PlayerSlot, player.HeroId)
} }
return buf.String() return strings.TrimSpace(buf.String())
} }
type DotaMatchPlayer struct { type DotaMatchPlayer struct {
@ -30,67 +32,107 @@ type DotaMatchPlayer struct {
HeroId int `json:"hero_id"` HeroId int `json:"hero_id"`
} }
/* type DotaMatchDetails struct {
{ RadiantWin bool `json:"radian_win"`
"match_id": 1680503925, Duration int `json:"duration"`
"match_seq_num": 1497692382, StartTime int `json:"start_time"`
"start_time": 1438511639, Id uint64 `json:"match_id"`
"lobby_type": 0, SeqNum uint64 `json:"match_seq_num"`
"radiant_team_id": 0, TowerStatusRadiant int `json:"tower_status_radiant"`
"dire_team_id": 0, TowerStatusDire int `json:"tower_status_dire"`
"players": [ Cluster int `json:"cluster"`
{ FirstBloodTime int `json:"first_blood_time"`
"account_id": 4294967295, LobbyTime int `json:"lobby_time"`
"player_slot": 0, HumanPlayers int `json:"human_players"`
"hero_id": 61 LeagueId int `json:"leagueid"`
}, PositiveVotes int `json:"positive_votes"`
{ NegativeVotes int `json:"negative_votes"`
"account_id": 4294967295, GameMode int `json:"game_mode"`
"player_slot": 1, Engine int `json:"engine"`
"hero_id": 56 Players []DotaMatchPlayerDetails `json:"players"`
}, }
{
"account_id": 4294967295, func (d DotaMatchDetails) Display(w io.Writer) {
"player_slot": 2, if d.RadiantWin {
"hero_id": 41 fmt.Fprintln(w, "Radiant Victory")
}, } else {
{ fmt.Fprintln(w, "Dire Victory")
"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
} }
] fmt.Fprintf(w, "Duration: %d\n", d.Duration)
fmt.Fprintf(w, "StartTime: %d\n", d.StartTime)
fmt.Fprintf(w, "Id: %d\n", d.Id)
fmt.Fprintf(w, "SeqNum: %d\n", d.SeqNum)
fmt.Fprintf(w, "TowerStatusRadiant: %d\n", d.TowerStatusRadiant)
fmt.Fprintf(w, "TowerStatusDire: %d\n", d.TowerStatusDire)
fmt.Fprintf(w, "Cluster: %d\n", d.Cluster)
fmt.Fprintf(w, "FirstBloodTime: %d\n", d.FirstBloodTime)
fmt.Fprintf(w, "LobbyTime: %d\n", d.LobbyTime)
fmt.Fprintf(w, "HumanPlayers: %d\n", d.HumanPlayers)
fmt.Fprintf(w, "LeagueId: %d\n", d.LeagueId)
fmt.Fprintf(w, "PositiveVotes: %d\n", d.PositiveVotes)
fmt.Fprintf(w, "NegativeVotes: %d\n", d.NegativeVotes)
fmt.Fprintf(w, "GameMode: %d\n", d.GameMode)
fmt.Fprintf(w, "Engine: %d\n", d.Engine)
for _, player := range d.Players {
player.Display(w)
}
}
}, type DotaMatchPlayerDetails struct {
AccountId uint64 `json:"account_id"`
PlayerSlot int `json:"player_slot"`
HeroId int `json:"hero_id"`
Item0 int `json:"item_0"`
Item1 int `json:"item_1"`
Item2 int `json:"item_2"`
Item3 int `json:"item_3"`
Item4 int `json:"item_4"`
Item5 int `json:"item_5"`
Kills int `json:"kills"`
Deaths int `json:"deaths"`
Assists int `json:"assists"`
LeaverStatus int `json:"leaver_status"`
Gold int `json:"gold"`
LastHits int `json:"last_hits"`
Denies int `json:"denies"`
GoldPerMinute int `json:"gold_per_min"`
XPPerMinute int `json:"xp_per_min"`
GoldSpent int `json:"gold_spent"`
HeroDamage int `json:"hero_damage"`
TowerDamage int `json:"tower_damage"`
HeroHealing int `json:"hero_healing"`
Level int `json:"level"`
AbilityUpgrades []DotaAbilityUpgrades `json:"ability_upgrades"`
}
*/ func (p DotaMatchPlayerDetails) Display(w io.Writer) {
fmt.Fprintf(w, "AccountId: %d\n", p.AccountId)
fmt.Fprintf(w, "PlayerSlot: %d\n", p.PlayerSlot)
fmt.Fprintf(w, "HeroId: %d\n", p.HeroId)
fmt.Fprintf(w, "Item0: %d\n", p.Item0)
fmt.Fprintf(w, "Item1: %d\n", p.Item1)
fmt.Fprintf(w, "Item2: %d\n", p.Item2)
fmt.Fprintf(w, "Item3: %d\n", p.Item3)
fmt.Fprintf(w, "Item4: %d\n", p.Item4)
fmt.Fprintf(w, "Item5: %d\n", p.Item5)
fmt.Fprintf(w, "Kills: %d\n", p.Kills)
fmt.Fprintf(w, "Deaths: %d\n", p.Deaths)
fmt.Fprintf(w, "Assists: %d\n", p.Assists)
fmt.Fprintf(w, "LeaverStatus: %d\n", p.LeaverStatus)
fmt.Fprintf(w, "Gold: %d\n", p.Gold)
fmt.Fprintf(w, "LastHits: %d\n", p.LastHits)
fmt.Fprintf(w, "Denies: %d\n", p.Denies)
fmt.Fprintf(w, "GoldPerMinute: %d\n", p.GoldPerMinute)
fmt.Fprintf(w, "XPPerMinute: %d\n", p.XPPerMinute)
fmt.Fprintf(w, "GoldSpent: %d\n", p.GoldSpent)
fmt.Fprintf(w, "HeroDamage: %d\n", p.HeroDamage)
fmt.Fprintf(w, "TowerDamage: %d\n", p.TowerDamage)
fmt.Fprintf(w, "HeroHealing: %d\n", p.HeroHealing)
fmt.Fprintf(w, "Level: %d\n", p.Level)
}
type DotaAbilityUpgrades struct {
Ability int `json:"ability"`
Time int `json:"time"`
Level int `json:"level"`
}

Loading…
Cancel
Save