-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (64 loc) · 1.48 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"database/sql"
"github.com/bwmarrin/lit"
"github.com/kkyr/fig"
"log"
_ "modernc.org/sqlite"
"strings"
"time"
tele "gopkg.in/telebot.v3"
)
var (
cfg config
cacheVideo map[string]*[]*tele.Video
cacheAlbum map[string]*[]*tele.Photo
cacheAudio map[string]*tele.Audio
db *sql.DB
)
func init() {
lit.LogLevel = lit.LogError
err := fig.Load(&cfg, fig.File("config.yml"), fig.Dirs(".", "./data"))
if err != nil {
lit.Error(err.Error())
return
}
// Set lit.LogLevel to the given value
switch strings.ToLower(cfg.LogLevel) {
case "logwarning", "warning":
lit.LogLevel = lit.LogWarning
case "loginformational", "informational":
lit.LogLevel = lit.LogInformational
case "logdebug", "debug":
lit.LogLevel = lit.LogDebug
}
cacheVideo = make(map[string]*[]*tele.Video)
cacheAlbum = make(map[string]*[]*tele.Photo)
cacheAudio = make(map[string]*tele.Audio)
// Open database connection
db, err = sql.Open("sqlite", "./data/cache.db")
if err != nil {
lit.Error("Error opening db connection, %s", err)
return
}
execQuery(videoTable, albumTable, audioTable)
load()
}
func main() {
// Create bot
pref := tele.Settings{
Token: cfg.Token,
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
}
b, err := tele.NewBot(pref)
if err != nil {
log.Fatal(err)
return
}
b.Handle(tele.OnQuery, inlineQuery)
b.Handle(tele.OnText, videoDownload)
// Start bot
lit.Info("videoDownloader is now running")
b.Start()
_ = db.Close()
}