diff --git a/game/game.go b/game/game.go index 650aa1b..0b9486b 100644 --- a/game/game.go +++ b/game/game.go @@ -1143,19 +1143,24 @@ func asyncStartGame(ctx context.Context, gameID *datastore.Key, host string) err } g.ID = gameID - gameStartedWebhook := g.DiscordWebhooks.GameStarted - // Invoke webhook using discordgo - if gameStartedWebhook.Id != "" && gameStartedWebhook.Token != "" { - discordSession, err := discordgo.New("Bot " + host) - if err != nil { - log.Errorf(ctx, "discordgo.New(...): %v", err) - return err - } - if err := discordSession.WebhookExecute(gameStartedWebhook.Id, gameStartedWebhook.Token, false, &discordgo.WebhookParams{ - Content: fmt.Sprintf("Game %v has started!", g.Desc), - }); err != nil { - log.Errorf(ctx, "discordSession.WebhookExecute(...): %v", err) - return err + discordBotToken, err := auth.GetDiscordBotToken(ctx) + if err != nil { + log.Warningf(ctx, "auth.GetDiscordBotToken(...): %v", err) + } else { + gameStartedWebhook := g.DiscordWebhooks.GameStarted + // Invoke webhook using discordgo + if gameStartedWebhook.Id != "" && gameStartedWebhook.Token != "" { + discordSession, err := discordgo.New("Bot " + discordBotToken.Token) + if err != nil { + log.Errorf(ctx, "discordgo.New(...): %v", err) + return err + } + if _, err := discordSession.WebhookExecute(gameStartedWebhook.Id, gameStartedWebhook.Token, false, &discordgo.WebhookParams{ + Content: fmt.Sprintf("Game %v has started!", g.Desc), + }); err != nil { + log.Errorf(ctx, "discordSession.WebhookExecute(...): %v", err) + return err + } } } diff --git a/game/phase.go b/game/phase.go index d632ef8..7fd86a9 100644 --- a/game/phase.go +++ b/game/phase.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/bwmarrin/discordgo" "github.com/dustin/go-humanize/english" "github.com/zond/diplicity/auth" "github.com/zond/godip" @@ -395,6 +396,33 @@ func sendPhaseNotificationsToFCM(ctx context.Context, host string, gameID *datas func sendPhaseNotificationsToUsers(ctx context.Context, host string, gameID *datastore.Key, phaseOrdinal int64, origUids []string) error { log.Infof(ctx, "sendPhaseNotificationsToUsers(..., %q, %v, %v, %+v)", host, gameID, phaseOrdinal, origUids) + g := &Game{} + if err := datastore.Get(ctx, gameID, g); err != nil { + log.Errorf(ctx, "datastore.Get(..., %v, %v): %v; hope datastore will get fixed", gameID, g, err) + return err + } + + discordBotToken, err := auth.GetDiscordBotToken(ctx) + if err != nil { + log.Warningf(ctx, "auth.GetDiscordBotToken(...): %v", err) + } else { + phaseStartedWebhook := g.DiscordWebhooks.PhaseStarted + // Invoke webhook using discordgo + if phaseStartedWebhook.Id != "" && phaseStartedWebhook.Token != "" { + discordSession, err := discordgo.New("Bot " + discordBotToken.Token) + if err != nil { + log.Errorf(ctx, "discordgo.New(...): %v", err) + return err + } + if _, err := discordSession.WebhookExecute(phaseStartedWebhook.Id, phaseStartedWebhook.Token, false, &discordgo.WebhookParams{ + Content: fmt.Sprintf("Phase %v has started!", phaseOrdinal), + }); err != nil { + log.Errorf(ctx, "discordSession.WebhookExecute(...): %v", err) + return err + } + } + } + if len(origUids) == 0 { log.Infof(ctx, "sendPhaseNotificationsToUsers(..., %q, %v, %v, %+v) *** NO UIDS ***", host, gameID, phaseOrdinal, origUids) return nil