master
Jordan Orelli 9 years ago
parent 910d60d8c0
commit 00b96760c9

@ -86,7 +86,7 @@ func (c *Client) GetPlayerSummaries(steamids ...uint64) ([]PlayerSummary, error)
}
func (c *Client) DotaMatchSequence(lastId uint64, n int) ([]DotaMatch, error) {
// http://api.steampowered.com/IDOTA2Match_<ID>/GetMatchHistoryBySequenceNum/v1
// http://api.steampowered.com/IDOTA2Match_<ID>/GetMatchHistoryBySequenceNum/v1
url := fmt.Sprintf("https://api.steampowered.com/IDOTA2Match_570/GetMatchHistoryBySequenceNum/v1/?key=%s", c.key)
if lastId > 0 {
url = fmt.Sprintf("%s&start_at_match_seq_num=%d", url, lastId)
@ -94,7 +94,7 @@ func (c *Client) DotaMatchSequence(lastId uint64, n int) ([]DotaMatch, error) {
if n > 0 {
url = fmt.Sprintf("%s&matches_requested=%d", url, n)
}
fmt.Println(url)
fmt.Println(url)
var response struct {
V struct {
Status int `json:"status"`
@ -122,7 +122,7 @@ func (c *Client) DotaMatchHistory(lastId uint64, n int) ([]DotaMatch, error) {
if n > 0 {
url = fmt.Sprintf("%s&matches_requested=%d", url, n)
}
fmt.Println(url)
fmt.Println(url)
var response struct {
V struct {
Status int `json:"status"`

@ -15,93 +15,12 @@ var commands map[string]command
func init() {
commands = map[string]command{
"api-list": command{
handler: func(c *steam.Client, args ...string) {
dump(c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001"))
},
},
"user-friends": command{
handler: func(c *steam.Client, args ...string) {
if len(args) < 1 {
bail(1, "please provide a user id")
}
userid, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
bail(1, "bad user id: %s", err)
}
friends, err := c.GetFriendList(userid)
if err != nil {
bail(1, "%v", err)
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
defer w.Flush()
for _, friend := range friends {
fmt.Fprintln(w, friend.Oneline())
}
},
},
"user-id": command{
handler: func(c *steam.Client, args ...string) {
userid, err := c.ResolveVanityUrl(args[0])
if err != nil {
bail(1, err.Error())
}
fmt.Println(userid)
},
},
"user-details": command{
handler: func(c *steam.Client, args ...string) {
if len(args) < 1 {
bail(1, "please provide a user id")
}
ids := make([]uint64, 0, len(args))
for _, arg := range args {
userid, err := strconv.ParseUint(arg, 10, 64)
if err != nil {
bail(1, "bad user id: %s", err)
}
ids = append(ids, userid)
}
players, err := c.GetPlayerSummaries(ids...)
if err != nil {
bail(1, "%v", err)
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
defer w.Flush()
for _, player := range players {
fmt.Fprintln(w, player.Oneline())
}
},
},
"dota-match-history": command{
handler: func(c *steam.Client, args ...string) {
matches, err := c.DotaMatchHistory(0, 0)
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())
}
},
},
"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)
},
},
"api-list": cmd_api_list,
"user-friends": cmd_user_friends,
"user-id": cmd_user_id,
"user-details": cmd_user_details,
"dota-match-history": cmd_dota_match_history,
"dota-match-details": cmd_dota_match_details,
"commands": command{
handler: func(c *steam.Client, args ...string) {
keys := make([]string, 0, len(commands))
@ -117,6 +36,99 @@ func init() {
}
}
var cmd_api_list = command{
handler: func(c *steam.Client, args ...string) {
dump(c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001"))
},
}
var cmd_user_friends = command{
handler: func(c *steam.Client, args ...string) {
if len(args) < 1 {
bail(1, "please provide a user id")
}
userid, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
bail(1, "bad user id: %s", err)
}
friends, err := c.GetFriendList(userid)
if err != nil {
bail(1, "%v", err)
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
defer w.Flush()
for _, friend := range friends {
fmt.Fprintln(w, friend.Oneline())
}
},
}
var cmd_user_id = command{
handler: func(c *steam.Client, args ...string) {
userid, err := c.ResolveVanityUrl(args[0])
if err != nil {
bail(1, err.Error())
}
fmt.Println(userid)
},
}
var cmd_user_details = command{
handler: func(c *steam.Client, args ...string) {
if len(args) < 1 {
bail(1, "please provide a user id")
}
ids := make([]uint64, 0, len(args))
for _, arg := range args {
userid, err := strconv.ParseUint(arg, 10, 64)
if err != nil {
bail(1, "bad user id: %s", err)
}
ids = append(ids, userid)
}
players, err := c.GetPlayerSummaries(ids...)
if err != nil {
bail(1, "%v", err)
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
defer w.Flush()
for _, player := range players {
fmt.Fprintln(w, player.Oneline())
}
},
}
var cmd_dota_match_history = command{
handler: func(c *steam.Client, args ...string) {
matches, err := c.DotaMatchHistory(0, 0)
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())
}
},
}
var cmd_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)
},
}
type command struct {
handler func(*steam.Client, ...string)
}

Loading…
Cancel
Save