match details

master
Jordan Orelli 9 years ago
parent cad49e6640
commit 482b77f766

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

@ -3,6 +3,8 @@ package steam
import (
"bytes"
"fmt"
"io"
"strings"
)
type DotaMatch struct {
@ -21,7 +23,7 @@ func (d DotaMatch) Oneline() string {
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()
return strings.TrimSpace(buf.String())
}
type DotaMatchPlayer struct {
@ -30,67 +32,107 @@ type DotaMatchPlayer struct {
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
}
]
type DotaMatchDetails struct {
RadiantWin bool `json:"radian_win"`
Duration int `json:"duration"`
StartTime int `json:"start_time"`
Id uint64 `json:"match_id"`
SeqNum uint64 `json:"match_seq_num"`
TowerStatusRadiant int `json:"tower_status_radiant"`
TowerStatusDire int `json:"tower_status_dire"`
Cluster int `json:"cluster"`
FirstBloodTime int `json:"first_blood_time"`
LobbyTime int `json:"lobby_time"`
HumanPlayers int `json:"human_players"`
LeagueId int `json:"leagueid"`
PositiveVotes int `json:"positive_votes"`
NegativeVotes int `json:"negative_votes"`
GameMode int `json:"game_mode"`
Engine int `json:"engine"`
Players []DotaMatchPlayerDetails `json:"players"`
}
func (d DotaMatchDetails) Display(w io.Writer) {
if d.RadiantWin {
fmt.Fprintln(w, "Radiant Victory")
} else {
fmt.Fprintln(w, "Dire Victory")
}
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