• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang tlbot.Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/igungor/tlbot.Message的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Message类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: runLocation

func runLocation(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	if len(args) == 0 {
		_, err := b.SendMessage(msg.Chat.ID, "nerenin konumunu arayayım?", nil)
		if err != nil {
			log.Printf("Error while sending message: %v\n", err)
		}
		return
	}
	u, err := url.Parse(mapBaseURL)
	if err != nil {
		log.Fatal(err)
	}
	googleAPIKey := ctx.Value("googleAPIKey").(string)
	place := strings.Join(args, " ")
	params := u.Query()
	params.Set("key", googleAPIKey)
	params.Set("query", place)
	u.RawQuery = params.Encode()

	resp, err := httpclient.Get(u.String())
	if err != nil {
		log.Printf("Error searching place '%v'. Err: %v\n", place, err)
		return
	}
	defer resp.Body.Close()

	var places placesResponse
	if err := json.NewDecoder(resp.Body).Decode(&places); err != nil {
		log.Printf("Error decoding response. Err: %v\n", err)
		return
	}

	if resp.StatusCode != http.StatusOK {
		log.Printf("Error searching place '%v'. Status: %v\n", place, places.Status)
		return
	}

	if len(places.Results) == 0 {
		_, err = b.SendMessage(msg.Chat.ID, "bulamadim", nil)
		if err != nil {
			log.Printf("Error while sending message: %v\n", err)
		}
		return
	}

	firstPlace := places.Results[0]
	location := tlbot.Location{
		Lat:  firstPlace.Geometry.Location.Lat,
		Long: firstPlace.Geometry.Location.Long,
	}
	_, err = b.SendLocation(msg.Chat.ID, location, nil)
	if err != nil {
		log.Printf("Error sending location: %v\n", err)
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:56,代码来源:location.go


示例2: runEcho

func runEcho(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	if len(args) == 0 {
		args = []string{"çok cahilsin"}
	}
	txt := fmt.Sprintf("*%v*", strings.Join(args, " "))
	_, err := b.SendMessage(msg.Chat.ID, txt, nil)
	if err != nil {
		log.Printf("Error while sending message: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:12,代码来源:echo.go


示例3: runForecast

func runForecast(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	var location string
	if len(args) == 0 {
		location = defaultCity
	} else {
		location = strings.Join(args, " ")
	}

	u, err := url.Parse(forecastURL)
	if err != nil {
		log.Printf("Error while parsing URL '%v'. Err: %v", forecastURL, err)
		return
	}

	forecastAPIKey := ctx.Value("openWeatherMapAppID").(string)

	params := u.Query()
	params.Set("units", "metric")
	params.Set("APPID", forecastAPIKey)
	params.Set("q", location)
	u.RawQuery = params.Encode()

	resp, err := http.Get(u.String())
	if err != nil {
		log.Printf("Error while fetching forecast for location '%v'. Err: %v\n", location, err)
		return
	}
	defer resp.Body.Close()

	var forecast Forecast
	if err := json.NewDecoder(resp.Body).Decode(&forecast); err != nil {
		log.Printf("Error while decoding response: %v\n", err)
		return
	}

	txt := forecast.String()
	if txt == "" {
		txt = fmt.Sprintf("%v bulunamadı.", location)
	}
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeMarkdown}
	_, err = b.SendMessage(msg.Chat.ID, txt, opts)
	if err != nil {
		log.Printf("Error while sending message. Err: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:47,代码来源:forecast.go


示例4: runMovie

func runMovie(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	opts := &tlbot.SendOptions{}
	if len(args) == 0 {
		term := randChoice(movieExamples)
		txt := fmt.Sprintf("hangi filmi arıyorsun? örneğin: */imdb %s*", term)
		opts.ParseMode = tlbot.ModeMarkdown
		_, err := b.SendMessage(msg.Chat.ID, txt, opts)
		if err != nil {
			log.Printf("Error while sending message: %v\n", err)
		}
		return
	}

	googleAPIKey := ctx.Value("googleAPIKey").(string)
	searchEngineID := ctx.Value("googleSearchEngineID").(string)

	// the best search engine is still google.
	// i've tried imdb, themoviedb, rottentomatoes, omdbapi.
	// themoviedb search engine was the most accurate yet still can't find any
	// result if any release date is given in query terms.
	urls, err := search(googleAPIKey, searchEngineID, "", args...)
	if err != nil {
		log.Printf("Error searching %v: %v\n", args, err)
		if err == errSearchQuotaExceeded {
			_, _ = b.SendMessage(msg.Chat.ID, `¯\_(ツ)_/¯`, opts)
		}
		return
	}

	for _, url := range urls {
		if strings.Contains(url, "imdb.com/title/tt") {
			_, err := b.SendMessage(msg.Chat.ID, url, opts)
			if err != nil {
				log.Printf("Error while sending message. Err: %v\n", err)
			}
			return
		}
	}

	opts.ParseMode = tlbot.ModeMarkdown
	_, err = b.SendMessage(msg.Chat.ID, "aradığın filmi bulamadım 🙈", opts)
	if err != nil {
		log.Printf("Error while sending message. Err: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:47,代码来源:movie.go


示例5: runWiki

func runWiki(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeMarkdown}
	if len(args) == 0 {
		txt := "neye referans vereyim? mesela bana bakın: */bkz İlber Ortaylı*"
		_, err := b.SendMessage(msg.Chat.ID, txt, opts)
		if err != nil {
			log.Printf("Error while sending message. Err: %v\n", err)
		}
		return
	}

	googleAPIKey := ctx.Value("googleAPIKey").(string)
	searchEngineID := ctx.Value("googleSearchEngineID").(string)

	terms := []string{"wikipedia"}
	terms = append(terms, args...)

	urls, err := search(googleAPIKey, searchEngineID, "", terms...)
	if err != nil {
		log.Printf("Error while 'bkz' query. Err: %v\n", err)
		if err == errSearchQuotaExceeded {
			b.SendMessage(msg.Chat.ID, `¯\_(ツ)_/¯`, nil)
		}
		return
	}

	for _, articleURL := range urls {
		if strings.Contains(articleURL, "wikipedia.org/wiki/") {
			_, err = b.SendMessage(msg.Chat.ID, articleURL, nil)
			if err != nil {
				log.Printf("Error while sending message. Err: %v\n", err)
				return
			}
			return
		}
	}

	_, err = b.SendMessage(msg.Chat.ID, "aradığın referansı bulamadım 🙈", opts)
	if err != nil {
		log.Printf("Error while sending message. Err: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:44,代码来源:wiki.go


示例6: runMe

func runMe(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	if len(args) == 0 {
		args = []string{"hmmmmm"}
	}

	user := msg.From.FirstName
	if user == "" {
		user = msg.From.Username
	}

	txt := fmt.Sprintf("`* %v %v`", user, strings.Join(args, " "))
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeMarkdown}
	_, err := b.SendMessage(msg.Chat.ID, txt, opts)
	if err != nil {
		log.Printf("Error while sending message: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:19,代码来源:me.go


示例7: runYo

func runYo(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeMarkdown}
	if len(args) == 0 {
		term := randChoice(yoExamples)
		txt := fmt.Sprintf("hangi karikatürü arıyorsun? örneğin: */yo %s*", term)
		_, err := b.SendMessage(msg.Chat.ID, txt, opts)
		if err != nil {
			log.Printf("Error while sending message: %v\n", err)
		}
		return
	}

	googleAPIKey := ctx.Value("googleAPIKey").(string)
	searchEngineID := ctx.Value("googleSearchEngineID").(string)

	terms := []string{"Yiğit", "Özgür"}
	terms = append(terms, args...)
	u, err := search(googleAPIKey, searchEngineID, "image", terms...)
	if err != nil {
		log.Printf("Error while searching image with given criteria: %v. Err: %v\n", args, err)
		if err == errSearchQuotaExceeded {
			_, _ = b.SendMessage(msg.Chat.ID, `¯\_(ツ)_/¯`, nil)
		}
		return
	}

	photo := tlbot.Photo{
		File: tlbot.File{
			URL: u[0],
		},
	}
	_, err = b.SendPhoto(msg.Chat.ID, photo, nil)
	if err != nil {
		log.Printf("Error while sending image: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:38,代码来源:yo.go


示例8: runImg

func runImg(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeNone}
	if len(args) == 0 {
		term := randChoice(imgExamples)
		txt := fmt.Sprintf("ne resmi aramak istiyorsun? örneğin: */img %s*", term)
		_, err := b.SendMessage(msg.Chat.ID, txt, opts)
		if err != nil {
			log.Printf("Error while sending message: %v\n", err)
		}
		return
	}

	googleAPIKey := ctx.Value("googleAPIKey").(string)
	searchEngineID := ctx.Value("googleSearchEngineID").(string)

	urls, err := search(googleAPIKey, searchEngineID, "image", args...)
	if err != nil {
		log.Printf("Error while searching image. Err: %v\n", err)
		if err == errSearchQuotaExceeded {
			_, _ = b.SendMessage(msg.Chat.ID, `¯\_(ツ)_/¯`, nil)
		}
		return
	}

	photo := tlbot.Photo{
		File: tlbot.File{
			URL: urls[0],
		},
	}

	_, err = b.SendPhoto(msg.Chat.ID, photo, nil)
	if err != nil {
		log.Printf("Error while sending photo: %v\n", err)
		return
	}
}
开发者ID:igungor,项目名称:ilber,代码行数:37,代码来源:img.go


示例9: runArxiv

func runArxiv(ctx context.Context, b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	opts := &tlbot.SendOptions{ParseMode: tlbot.ModeNone}
	if len(args) == 0 {
		opts := &tlbot.SendOptions{ParseMode: tlbot.ModeMarkdown}
		_, err := b.SendMessage(msg.Chat.ID, "boş geçmeyelim  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errs.Check函数代码示例发布时间:2022-05-28
下一篇:
Golang tlbot.Bot类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap