-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (38 loc) · 1.16 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 (
bot "lit-night-bot/bot"
"lit-night-bot/cron"
io "lit-night-bot/io"
"lit-night-bot/tasks"
"github.com/sirupsen/logrus"
)
func getBot(logger *logrus.Entry, iocd *io.IoChatData, token string, isDebug bool) *bot.LitNightBot {
bot, err := bot.NewLitNightBot(logger, token, iocd, isDebug)
if err != nil {
panic(err)
}
return bot
}
func getLogger(isDebug bool) *logrus.Entry {
logger := logrus.New()
if isDebug {
logger.SetLevel(logrus.DebugLevel)
logger.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
} else {
logger.SetLevel(logrus.InfoLevel)
logger.SetFormatter(&logrus.JSONFormatter{})
}
return logger.WithField("project", "lit-night-bot")
}
func main() {
config := GetConfig()
logger := getLogger(config.isDebug)
iocd := io.NewIOChatData(logger.WithField("entry", "iocd"), config.dataPath)
lnb := getBot(logger.WithField("entry", "bot"), iocd, config.token, config.isDebug)
cronTasks := []tasks.Task{
*tasks.Remind("0 7 * * *", tasks.OneWeekReminderJokes, 7),
*tasks.Remind("0 7 * * *", tasks.OneDayReminderJokes, 1),
}
lnb.Start()
cron.StartCron(logger.WithField("entry", "cron"), iocd, lnb, &cronTasks)
}