/
yo.go
67 lines (59 loc) · 1.41 KB
/
yo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package command
import (
"context"
"fmt"
"github.com/igungor/ilber/bot"
"github.com/igungor/telegram"
)
func init() {
register(cmdYo)
}
var cmdYo = &Command{
Name: "yo",
ShortLine: "yiğit özgür şeysi",
Run: runYo,
}
func runYo(ctx context.Context, b *bot.Bot, msg *telegram.Message) {
args := msg.Args()
md := telegram.WithParseMode(telegram.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, md)
if err != nil {
b.Logger.Printf("Error while sending message: %v\n", err)
}
return
}
terms := []string{"Yiğit", "Özgür"}
terms = append(terms, args...)
u, err := search(b.Config.GoogleAPIKey, b.Config.GoogleSearchEngineID, "image", terms...)
if err != nil {
b.Logger.Printf("Error while searching image with given criteria: %v. Err: %v\n", args, err)
if err == errSearchQuotaExceeded {
_, _ = b.SendMessage(msg.Chat.ID, emojiShrug)
}
return
}
photo := telegram.Photo{
File: telegram.File{
URL: u[0],
},
}
_, err = b.SendPhoto(msg.Chat.ID, photo)
if err != nil {
b.Logger.Printf("Error while sending image: %v\n", err)
return
}
}
var yoExamples = []string{
"renk dans",
"bağa mı didin",
"düşünemedi",
"lütfen olsun çünkü",
"geldi yine",
"sipirmin",
"lanet olsun sana",
"flemenko",
"anamı karıştırma",
}