Example #1
0
func getLtc(_ commands.Message, ret commands.MessageFunc) string {
	btce, err := util.Fetch("https://btc-e.com/api/2/ltc_usd/ticker")
	if err != nil {
		return fmt.Sprintf("[%s]: BTC-E Error!", util.Bold("BTC-E"))
	}

	var response btceResponse
	if err := json.Unmarshal(btce, &response); err != nil {
		return fmt.Sprintf("[%s]: BTC-E Error!", util.Bold("BTC-E"))
	}
	return fmt.Sprintf("LTC->USD: Last: $%v, High: $%v, Low: $%v, Avg: $%v",
		response.Ticker.Last, response.Ticker.High, response.Ticker.Low, response.Ticker.Avg)
}
Example #2
0
func getBitstamp(ch chan string) {
	bitstamp, err := util.Fetch("https://www.bitstamp.net/api/ticker/")
	if err != nil {
		ch <- fmt.Sprintf("[%s]: BitStamp Error!", util.Bold("BITSTAMP"))
		return
	}
	var btresponse bitstampResponse
	if err := json.Unmarshal(bitstamp, &btresponse); err != nil {
		ch <- fmt.Sprintf("[%s]: BitStamp Error!", util.Bold("BITSTAMP"))
		return
	}
	out := fmt.Sprintf("[%s]: Last: $%s, High: $%s, Low: $%s", util.Bold("BITSTAMP"), btresponse.Last, btresponse.High, btresponse.Low)
	ch <- out
}
Example #3
0
func getBTCE(ch chan string) {
	btce, err := util.Fetch("https://btc-e.com/api/2/btc_usd/ticker")
	if err != nil {
		ch <- fmt.Sprintf("[%s]: BTC-E Error!", util.Bold("BTC-E"))
	}

	var response btceResponse
	if err := json.Unmarshal(btce, &response); err != nil {
		ch <- fmt.Sprintf("[%s]: BTC-E Error!", util.Bold("BTC-E"))
		return
	}
	out := fmt.Sprintf("[%s]: Last: $%v, High: $%v, Low: $%v, Avg: $%v", util.Bold("BTC-E"), response.Ticker.Last, response.Ticker.High, response.Ticker.Low, response.Ticker.Avg)
	ch <- out
}
Example #4
0
func urbanLookup(msg commands.Message, ret commands.MessageFunc) string {
	search := strings.Join(msg.Params[1:], " ")
	url := fmt.Sprintf("%s%s", urbanapi, util.URLEncode(search))
	data, err := util.Fetch(url)
	if err != nil {
		return "Error trying to find that!"
	}
	var ud urbanInfo
	if err := json.Unmarshal(data, &ud); err != nil {
		return "Urban Dictionary gave me a bad response!"
	}
	if len(ud.List) == 0 {
		return "I didn't get anything for that!"
	}

	return fmt.Sprintf("%s: %s", util.Bold(search), ud.List[0].Definition)

}