2019-05-10 08:21:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2019-05-10 08:53:58 +00:00
|
|
|
"galched-bot/modules/discord"
|
2019-05-10 08:21:59 +00:00
|
|
|
"galched-bot/modules/grace"
|
|
|
|
"galched-bot/modules/settings"
|
|
|
|
|
|
|
|
"go.uber.org/fx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
silentPrinter struct{}
|
|
|
|
|
|
|
|
appParam struct {
|
|
|
|
fx.In
|
|
|
|
|
|
|
|
Context context.Context
|
2019-05-10 08:53:58 +00:00
|
|
|
Discord *discord.Discord
|
|
|
|
Settings *settings.Settings
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *silentPrinter) Printf(str string, i ...interface{}) {}
|
|
|
|
|
|
|
|
func start(p appParam) {
|
2019-05-10 08:53:58 +00:00
|
|
|
var err error
|
|
|
|
|
2019-05-10 08:21:59 +00:00
|
|
|
log.Print("main: starting galched-bot v", p.Settings.Version)
|
2019-05-10 08:53:58 +00:00
|
|
|
|
|
|
|
err = p.Discord.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("discord: cannot start instance", err)
|
|
|
|
}
|
2019-05-10 09:55:52 +00:00
|
|
|
log.Printf("main: discord instance running")
|
|
|
|
log.Printf("main: — — —")
|
2019-05-10 08:53:58 +00:00
|
|
|
|
2019-05-10 08:21:59 +00:00
|
|
|
<-p.Context.Done()
|
2019-05-10 08:53:58 +00:00
|
|
|
log.Print("main: stopping galched-bot")
|
|
|
|
|
|
|
|
err = p.Discord.Stop()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("discord: cannot stop instance", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("main: galched bot successfully stopped")
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
app := fx.New(
|
|
|
|
fx.Logger(new(silentPrinter)),
|
2019-05-10 08:53:58 +00:00
|
|
|
fx.Provide(settings.New, grace.New, discord.New),
|
2019-05-10 08:21:59 +00:00
|
|
|
fx.Invoke(start))
|
|
|
|
|
|
|
|
err = app.Start(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|