-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (42 loc) · 1.21 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
package main
import (
"database/sql"
"hometown-bot/bot"
"hometown-bot/log"
"hometown-bot/repository"
"hometown-bot/storage"
"os"
)
func main() {
log.Info().Println("env: reading keys")
botToken, ok := os.LookupEnv("BOT_TOKEN")
if !ok {
log.Error().Println("env: key BOT_TOKEN is empty or not set")
os.Exit(1)
}
log.Info().Println("storage: initializing")
db, err := storage.Load()
if err != nil {
log.Error().Printf("storage: %v", err)
os.Exit(1)
}
defer func(db *sql.DB) {
log.Info().Println("storage: closing")
err := db.Close()
if err != nil {
log.Error().Printf("storage: %v", err)
os.Exit(1)
}
}(db)
log.Info().Println("repository: initializing")
channelRepository := repository.NewChannel(db)
channelMembersRepository := repository.NewChannelMembers(db)
lobbyRepository := repository.NewLobby(db)
log.Info().Println("bot: initializing")
bot.Token = botToken
b := bot.Create(*channelRepository, *channelMembersRepository, *lobbyRepository)
if err := b.Run(); err != nil {
log.Error().Printf("bot: %v", err)
os.Exit(1)
}
}