forked from MrMarble/teledock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (58 loc) · 1.59 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
package main
import (
"os"
"strings"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var (
bot *Telegram = nil
superAdmins []int64 = []int64{}
docker *Docker = nil
)
func main() {
// Configure logger
zerolog.TimeFieldFormat = time.RFC3339
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if os.Getenv("TELEDOCK_DEBUG") == "true" {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339})
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Logger = log.With().Caller().Logger()
//Check required env vars
for _, envVar := range []string{
"TELEDOCK_TOKEN",
"TELEDOCK_SUPERADMINS",
} {
if os.Getenv(envVar) == "" {
log.Fatal().Str("module", "main").Str("envvar", envVar).Msg("missing environment variable")
}
}
// Load superadmin list
if envsa := os.Getenv("TELEDOCK_SUPERADMINS"); envsa != "" {
for _, uidStr := range strings.Split(envsa, ",") {
uid, errp := parseInt64(uidStr)
if errp != nil {
log.Fatal().Str("module", "main").Err(errp).Msg("failed parsing superadmins list")
}
superAdmins = append(superAdmins, uid)
}
}
log.Info().Str("module", "main").Ints64("user_ids", superAdmins).Msg("loaded superadmins")
// Connect to docker
var err error
docker, err = newDocker()
if err != nil {
log.Fatal().Str("module", "main").Err(err).Msg("failed to connect to docker")
}
// Ping the daemon
docker.ping()
// Create bot
bot, err = NewBot(os.Getenv("TELEDOCK_TOKEN"))
if err != nil {
log.Fatal().Str("module", "main").Err(err).Msg("failed bot instantiaion")
}
// Start the bot
bot.Start()
}