-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (47 loc) · 1.14 KB
/
main.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
package main
import (
"log"
"strings"
"time"
"cryptoTelegramBot/config"
"cryptoTelegramBot/handler"
"cryptoTelegramBot/repo"
"cryptoTelegramBot/utils"
tb "gopkg.in/tucnak/telebot.v2"
)
func main() {
repo.Start_db()
repo.Create_tables()
b, err := tb.NewBot(tb.Settings{
// You can set custom API URL. If empty it equals to "https://api.telegram.org".
Token: config.LoadConfig().Token,
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})
if err != nil {
log.Fatal(err)
return
}
for k, v := range handler.LoadHandler(b) {
b.Handle(k, v)
log.Println(k + "✅ Loaded!")
}
b.Handle(tb.OnText, func(m *tb.Message) {
log.Println(m.Text)
if strings.Contains(strings.ToLower(m.Text), "crypto") {
g := &tb.Animation{File: tb.FromURL("https://c.tenor.com/hJ834RcJZbYAAAAC/elon-musk-dance.gif")}
log.Printf("struct1: %v\n", m.Chat)
b.Send(m.Chat, "Someone said crypto???")
b.Send(m.Chat, g)
}
})
log.Println("OnText ✅ Loaded!")
func1 := func() {
// blocks until shutdown
b.Start()
}
channel := make(chan string)
func2 := func() {
handler.PullNotifications(channel, b)
}
utils.Parallelize(func1, func2)
}