Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &commands.YAGCommand{ Cooldown: 5, CmdCategory: commands.CategoryFun, Name: "Advice", Description: "Get advice", Arguments: []*dcmd.ArgDef{ &dcmd.ArgDef{Name: "What", Type: dcmd.String}, }, RunFunc: func(data *dcmd.Data) (interface{}, error) { random := true addr := "http://api.adviceslip.com/advice" if data.Args[0].Str() != "" { random = false addr = "http://api.adviceslip.com/advice/search/" + url.QueryEscape(data.Args[0].Str()) } resp, err := http.Get(addr) if err != nil { return nil, err } var decoded interface{} if random { decoded = &RandomAdviceResp{} } else { decoded = &SearchAdviceResp{} } err = json.NewDecoder(resp.Body).Decode(&decoded) if err != nil { return err, err } advice := "No advice found :'(" if random { slip := decoded.(*RandomAdviceResp).Slip if slip != nil { advice = slip.Advice } } else { cast := decoded.(*SearchAdviceResp) if len(cast.Slips) > 0 { advice = cast.Slips[0].Advice } } return advice, nil }, }
Functions ¶
This section is empty.
Types ¶
type AdviceSlip ¶
type RandomAdviceResp ¶
type RandomAdviceResp struct {
Slip *AdviceSlip `json:"slip"`
}
type SearchAdviceResp ¶
type SearchAdviceResp struct { TotalResults json.Number `json:"total_results"` Slips []*AdviceSlip `json:"slips"` }
Click to show internal directories.
Click to hide internal directories.