Example #1
0
func SendLocation(chat_id int, longitude float64, latitude float64) {

	// 'f'?
	resp, err := http.PostForm(config.ApiUrl+config.Token+"/sendLocation", url.Values{"chat_id": {strconv.Itoa(chat_id)}, "latitude": {strconv.FormatFloat(latitude, 'f', 6, 64)}, "longitude": {strconv.FormatFloat(longitude, 'f', 6, 64)}})
	defer resp.Body.Close()
	util.PanicIf(err)
}
Example #2
0
/*
	strconv.Itoa()
	not
	string()
*/
func SendMessage(chat_id int, text string) {

	resp, err := http.PostForm(config.ApiUrl+config.Token+"/sendMessage", url.Values{"chat_id": {strconv.Itoa(chat_id)}, "text": {text}})

	defer resp.Body.Close()
	util.PanicIf(err)
}
Example #3
0
func SearchInGoogle(query string) []string {

	resp, err := http.Get("https://www.google.com/search?q=" + url.QueryEscape(query))
	util.PanicIf(err)

	ret, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	util.PanicIf(err)

	doc, _ := html.Parse(strings.NewReader(string(ret)))

	var links []string
	getLinks(doc, &links)

	return links
}
Example #4
0
func main() {

	config = common.GetConfig()

	http.HandleFunc("/", serveHomePage)
	http.Handle("/assets/", http.FileServer(http.Dir("templates/")))

	webHookUrl := biubot.GetWebHookUrl()
	http.HandleFunc(webHookUrl, serveWebHook)

	hostname, _ := os.Hostname()
	// auto change
	if hostname != "jsxqfdeMac-mini.local" {
		err := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
		util.PanicIf(err)
	} else {
		err := http.ListenAndServe(":8080", nil)
		util.PanicIf(err)
	}

}
Example #5
0
func GetUpdates() (updates []Update) {

	resp, err := http.Get(config.ApiUrl + config.Token + "/getUpdates")
	util.PanicIf(err)
	body, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	type Data struct {
		Ok     bool
		Result []Update
	}
	var data Data
	json.Unmarshal(body, &data)

	updates = data.Result
	return
}
Example #6
0
func SendPhoto(chat_id int, photo_id string) {

	resp, err := http.PostForm(config.ApiUrl+config.Token+"/sendPhoto", url.Values{"chat_id": {strconv.Itoa(chat_id)}, "photo": {photo_id}})
	defer resp.Body.Close()
	util.PanicIf(err)
}