2019-05-10 08:21:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2020-01-11 19:38:51 +00:00
|
|
|
"go.uber.org/fx"
|
|
|
|
|
2019-05-10 08:53:58 +00:00
|
|
|
"galched-bot/modules/discord"
|
2019-05-10 08:21:59 +00:00
|
|
|
"galched-bot/modules/grace"
|
2020-03-18 19:33:33 +00:00
|
|
|
"galched-bot/modules/patpet"
|
2019-05-10 08:21:59 +00:00
|
|
|
"galched-bot/modules/settings"
|
2019-05-10 12:16:35 +00:00
|
|
|
"galched-bot/modules/subday"
|
2019-06-23 13:12:35 +00:00
|
|
|
"galched-bot/modules/twitchat"
|
2020-01-11 19:38:51 +00:00
|
|
|
"galched-bot/modules/web"
|
|
|
|
"galched-bot/modules/youtube"
|
2019-05-10 08:21:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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-06-23 13:12:35 +00:00
|
|
|
Chat *twitchat.TwitchIRC
|
2020-01-11 19:38:51 +00:00
|
|
|
Server *web.WebServer
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *silentPrinter) Printf(str string, i ...interface{}) {}
|
|
|
|
|
2019-05-10 12:16:35 +00:00
|
|
|
func start(p appParam) error {
|
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 {
|
2019-05-10 12:16:35 +00:00
|
|
|
log.Print("discord: cannot start instance", err)
|
|
|
|
return err
|
2019-05-10 08:53:58 +00:00
|
|
|
}
|
2019-05-10 09:55:52 +00:00
|
|
|
log.Printf("main: discord instance running")
|
2019-05-10 08:53:58 +00:00
|
|
|
|
2019-06-23 13:12:35 +00:00
|
|
|
err = p.Chat.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.Print("chat: cannot start instance", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Printf("main: twitch chat instance running")
|
|
|
|
|
2020-01-11 19:38:51 +00:00
|
|
|
err = p.Server.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.Print("web: cannot start instance", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Printf("main: web server instance running")
|
|
|
|
|
2019-06-23 13:12:35 +00:00
|
|
|
log.Printf("main: — — —")
|
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")
|
|
|
|
|
2020-01-11 19:38:51 +00:00
|
|
|
err = p.Server.Stop(p.Context)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("web: cannot stop instance", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-23 13:12:35 +00:00
|
|
|
err = p.Chat.Stop()
|
|
|
|
if err != nil {
|
|
|
|
log.Print("chat: cannot stop instance", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-10 08:53:58 +00:00
|
|
|
err = p.Discord.Stop()
|
|
|
|
if err != nil {
|
2019-05-10 12:16:35 +00:00
|
|
|
log.Print("discord: cannot stop instance", err)
|
|
|
|
return err
|
2019-05-10 08:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("main: galched bot successfully stopped")
|
2019-05-10 12:16:35 +00:00
|
|
|
return nil
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
app := fx.New(
|
|
|
|
fx.Logger(new(silentPrinter)),
|
2020-03-18 19:33:33 +00:00
|
|
|
fx.Provide(settings.New, grace.New, discord.New, subday.New,
|
|
|
|
twitchat.New, web.New, youtube.New, patpet.New),
|
2019-05-10 08:21:59 +00:00
|
|
|
fx.Invoke(start))
|
|
|
|
|
|
|
|
err = app.Start(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|