func cotacao(command *bot.Cmd) (msg string, err error) { data := &retorno{} err = web.GetJSON(url, data) if err != nil { return "", err } return fmt.Sprintf("Dólar: %s (%s), Euro: %s (%s)", data.Dolar.Cotacao, data.Dolar.Variacao, data.Euro.Cotacao, data.Euro.Variacao), nil }
func gif(command *bot.Cmd) (msg string, err error) { data := &giphy{} err = web.GetJSON(fmt.Sprintf(giphyURL, url.QueryEscape(command.FullArg)), data) if err != nil { return "", err } if len(data.Data) == 0 { return "No gifs found. try: !gif cat", nil } index := rand.Intn(len(data.Data)) return fmt.Sprintf(data.Data[index].Images.FixedHeight.URL), nil }
func resultado() (string, error) { data := &retorno{} err := web.GetJSON(url, data) if err != nil { return "", err } return fmt.Sprintf("Sorteio %s de %s: %s - %s premiado(s) R$ %s.", data.Concurso.Numero, data.Concurso.Data, data.Concurso.NumerosSorteados, data.Concurso.Premiacao.Sena.Ganhadores, data.Concurso.Premiacao.Sena.ValorPago), nil }
func catFacts(command *bot.PassiveCmd) (string, error) { if !re.MatchString(command.Raw) { return "", nil } data := &facts{} err := web.GetJSON(catFactsURL, data) if err != nil { return "", err } if len(data.Facts) == 0 { return "", nil } return fmt.Sprintf(msgPrefix, data.Facts[0]), nil }
func search(cmd *bot.Cmd) (string, error) { if cmd.FullArg == "" { return "", nil } data := &godocResults{} url, _ := url.Parse(godocSearchURL) q := url.Query() q.Set("q", cmd.FullArg) url.RawQuery = q.Encode() err := web.GetJSON(url.String(), data) if err != nil { return "", err } if len(data.Results) == 0 { return noPackagesFound, nil } return fmt.Sprintf("%s %s/%s", data.Results[0].Synopsis, godocSiteURL, data.Results[0].Path), nil }