package main // import "git.fromouter.space/mcg/mlp-server-tools/draftbot" import ( "errors" "flag" "fmt" "os" "os/signal" "syscall" "git.fromouter.space/Artificiale/moa/sd" "git.fromouter.space/mcg/cardgage/client/bot" "github.com/go-kit/kit/log" ) var logger log.Logger func main() { consulAddr := flag.String("consul.addr", "consul:8500", "Consul address") logger = log.NewLogfmtLogger(os.Stderr) logger = log.With(logger, "ts", log.DefaultTimestampUTC) logger = log.With(logger, "caller", log.DefaultCaller) // Register with consul registrar := sd.Register(*consulAddr, sd.Options{ Name: "draftbot", Tags: []string{ "bot", // I am a room bot }, }, logger) defer registrar.Deregister() // Initialize consul client for service discovery sd.InitClient(*consulAddr) errs := make(chan error) go func() { c := make(chan os.Signal) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) errs <- fmt.Errorf("%s", <-c) }() go func() { errs <- runBot() }() logger.Log("exit", <-errs) } func runBot() error { // Search for roomsvc roomsvc, err := sd.GetOne("roomsvc") if err != nil { return err } addr := fmt.Sprintf("ws://%s:%d/bot", roomsvc.Service.Address, roomsvc.Service.Port) wsbot, err := bot.NewBot(addr, bot.Params{ Name: "Draftbot", MsgBufferSize: 10, Logger: logger, GameIDs: []string{"mlpccg-mcg"}, Tags: []string{"draft"}, }) if err != nil { return err } draftbot := newDraftBot() wsbot.Listen(draftbot.onMessage) return errors.New("eof") }