This repository was archived by the owner on Apr 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
57 lines (46 loc) · 1.33 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
package main
import (
"flag"
log "github.com/kirillDanshin/dlog"
"gitlab.com/toby3d/mypackbot/internal/bot"
"gitlab.com/toby3d/mypackbot/internal/config"
"gitlab.com/toby3d/mypackbot/internal/db"
"gitlab.com/toby3d/mypackbot/internal/errors"
"gitlab.com/toby3d/mypackbot/internal/i18n"
"gitlab.com/toby3d/mypackbot/internal/updates"
)
var flagWebhook = flag.Bool(
"webhook", false,
"enable work via webhooks (required valid certificates)",
)
// init prepare configuration and other things for successful start
func init() {
log.Ln("Initializing...")
// Preload localization strings
err := i18n.Open("i18n/")
errors.Check(err)
// Preload configuration file
config.Open("configs/config.yaml")
// Open database or create new one
db.Open("stickers.db")
// Create bot with credentials from config
bot.Bot, err = bot.New(config.Config.GetString("telegram.token"))
errors.Check(err)
}
// main function is a general function for work of this bot
func main() {
flag.Parse() // Parse flagWebhook
channel, err := updates.Channel(*flagWebhook)
errors.Check(err)
for update := range channel {
log.D(update)
switch {
case update.IsInlineQuery():
updates.InlineQuery(update.InlineQuery)
case update.IsMessage():
updates.Message(update.Message)
case update.IsChannelPost():
updates.ChannelPost(update.ChannelPost)
}
}
}