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 } }
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 } }