This commit adds config values to the config package for state configuration. This commit also adds a call to state.Init() to the main function. Signed-off-by: Ava Affine <ava@sunnypup.io>
61 lines
941 B
Go
61 lines
941 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"gitlab.com/whom/bingobot/internal/config"
|
|
"gitlab.com/whom/bingobot/internal/discord"
|
|
"gitlab.com/whom/bingobot/internal/logging"
|
|
"gitlab.com/whom/bingobot/internal/state"
|
|
)
|
|
|
|
var (
|
|
token = flag.String("token", "", "Bot authentication token")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var err error
|
|
|
|
err = config.Init()
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
logging.Init()
|
|
|
|
if err := state.Init(
|
|
config.Get().InMemoryEventCacheSize,
|
|
config.Get().PersistentCacheStore,
|
|
); err != nil {
|
|
log.Fatalf("couldn't initialize state engine: %s", err.Error())
|
|
}
|
|
|
|
err = startBot()
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func startBot() error {
|
|
err := discord.Connect(*token)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sigch := make(chan os.Signal, 1)
|
|
signal.Notify(sigch, os.Interrupt)
|
|
<-sigch
|
|
|
|
logging.Info("shutting down gracefully", "type", "shutdown")
|
|
discord.Close()
|
|
|
|
return nil
|
|
}
|