コード例 #1
0
ファイル: urban.go プロジェクト: nickvanw/bogon
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)

}
コード例 #2
0
ファイル: wolfram.go プロジェクト: nickvanw/bogon
func wolframLookup(msg commands.Message, ret commands.MessageFunc) string {
	appid, avail := config.Get("WOLFRAM_API")
	if avail != true {
		return ""
	}
	query := util.URLEncode(strings.Join(msg.Params[1:], " "))
	getURL := fmt.Sprintf("%s?input=%s&appid=%s", geturl, query, appid)
	resp, err := util.Fetch(getURL)
	if err != nil {
		return "Wolfram returned an error!"
	}
	var d result
	if err := xml.Unmarshal(resp, &d); err != nil {
		fmt.Println(err)
		return "Wolfram did not return valid data!"
	}
	if len(d.Pods) < 2 && len(d.Pods[0].Subpods) > 0 && len(d.Pods[1].Subpods) > 0 {
		return "Wolfram did not return valid data!"
	}

	return fmt.Sprintf("wa: q: %s, a: %s", d.Pods[0].Subpods[0].Plaintext, removeNewLineUntil(d.Pods[1].Subpods[0].Plaintext, 200))
}