Exemplo n.º 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
}
Exemplo n.º 2
0
func catFactsRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)\b(cat|gato|miau|meow|garfield|lolcat)[s|z]?\b`, false)
	for {
		pm := <-cb.Chan
		data := &facts{}
		err := web.GetJSON(catFactsURL, data)
		if err != nil || len(data.Facts) == 0 {
			return
		}
		pm.Event.Respond(fmt.Sprintf("I love cats! Here's a fact: %v", data.Facts[0]))
	}
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
func Resultado() string {
	data := &Retorno{}
	err := web.GetJSON(URL, data)
	if err != nil {
		return err.Error()
	}

	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)
}
Exemplo n.º 5
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
}
Exemplo n.º 6
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
}
Exemplo n.º 7
0
func goDocRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)^godoc ([^\s]+)$`, false)
	for {
		pm := <-cb.Chan
		data := &godocResults{}

		url, _ := url.Parse(godocSearchURL)
		q := url.Query()
		q.Set("q", pm.Match[1])
		url.RawQuery = q.Encode()
		err := web.GetJSON(url.String(), data)
		if err != nil {
			pm.Event.Respond(fmt.Sprintf("Error: ", err.Error()))
		}

		if len(data.Results) == 0 {
			pm.Event.Respond(noPackagesFound)
		}
		a := []lazlo.Attachment{
			lazlo.Attachment{
				Color:      "#ff0000",
				Title:      fmt.Sprintf(`Results of "%v"`, pm.Match[1]),
				MarkdownIn: []string{"fields"},
				Fields:     []lazlo.AttachmentField{},
			},
		}

		for i := 0; i < len(data.Results); i++ {
			if i == 10 {
				break
			}
			if data.Results[i].Synopsis == "" {
				data.Results[i].Synopsis = "_No description_"
			}
			a[0].Fields = append(a[0].Fields, lazlo.AttachmentField{
				Title: fmt.Sprintf("%s", data.Results[i].Path),
				Value: fmt.Sprintf("%s\n<%s/%s|full GoDoc>", data.Results[i].Synopsis, godocSiteURL, data.Results[i].Path),
			})
		}

		pm.Event.RespondAttachments(a)
	}
}
Exemplo n.º 8
0
func gif(command *bot.Cmd) (msg string, err error) {
	if command.Nick == "nathan" || (strings.Contains(strings.ToLower(command.FullArg), "nathan")) {
		return "http://gwenstephens.files.wordpress.com/2013/03/mullet-hairstyles-mullet.jpg", nil
	}

	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
	}

	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	index := r.Intn(len(data.Data))
	return fmt.Sprintf(data.Data[index].Images.FixedHeight.Url), nil
}
Exemplo n.º 9
0
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
}