Пример #1
0
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
}
Пример #2
0
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
}
Пример #3
0
func gif(command *bot.Cmd) (msg string, err error) {
	data := &giphy{}
	err = web.GetJSON(fmt.Sprintf(giphyURL, url.QueryEscape(command.RawArgs)), 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
}
Пример #4
0
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
}
Пример #5
0
func search(cmd *bot.Cmd) (string, error) {
	if cmd.RawArgs == "" {
		return "", nil
	}

	data := &godocResults{}

	url, _ := url.Parse(godocSearchURL)
	q := url.Query()
	q.Set("q", cmd.RawArgs)
	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
}