forked from Southclaws/cj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_core.go
51 lines (43 loc) · 1.02 KB
/
bot_core.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
package main
import (
"net/http"
"os"
"time"
"github.com/bwmarrin/discordgo"
"github.com/patrickmn/go-cache"
"go.uber.org/zap"
"gopkg.in/mgo.v2"
)
// App stores program state
type App struct {
config Config
mongo *mgo.Session
accounts *mgo.Collection
chat *mgo.Collection
discordClient *discordgo.Session
httpClient *http.Client
ready chan bool
cache *cache.Cache
locale Locale
commandManager *CommandManager
}
// Start starts the app with the specified config and blocks until fatal error
func Start(config Config) {
app := App{
config: config,
httpClient: &http.Client{},
cache: cache.New(5*time.Minute, 30*time.Second),
}
configLocation := os.Getenv("CONFIG_FILE")
if configLocation == "" {
configLocation = "config.json"
}
logger.Debug("started with debug logging enabled",
zap.Any("config", app.config))
app.ConnectDB()
app.LoadLanguages()
app.StartCommandManager()
app.ConnectDiscord()
done := make(chan bool)
<-done
}