-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
50 lines (47 loc) · 1.19 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
package main
import (
"github.com/alexkarlov/15x4bot/bot"
"github.com/alexkarlov/15x4bot/commands"
"github.com/alexkarlov/15x4bot/scheduler"
"github.com/alexkarlov/simplelog"
"os"
"os/signal"
"syscall"
"github.com/alexkarlov/15x4bot/config"
"github.com/alexkarlov/15x4bot/store"
"github.com/antonmashko/envconf"
_ "github.com/lib/pq"
)
func main() {
var conf config.Config
err := envconf.Parse(&conf)
if err != nil {
panic(err)
}
log.SetLevel(log.LogLevel(conf.LogLevel))
log.Infof("Configs: %#v", conf)
// setup DB config and establish connection
store.Conf = conf.DB
if err = store.Init(); err != nil {
panic(err)
}
// setup bot config and run bot
bot.Conf = conf.TG
bot, err := bot.NewBot()
if err != nil {
panic(err)
}
// setup commands config
commands.Conf = conf.Chat
// start listening updates
go bot.ListenUpdates()
// start background job manager
go scheduler.Run(bot)
// wating for signals (SIGTERM - correct exit from application)
log.Info("app has been started. waiting for signals")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
// TODO: finalise all active chats
log.Infof("got signal %s.exiting...", sig)
}