Fix: save bot actions
This commit is contained in:
@ -152,7 +152,18 @@ func (b *Bot) checkGuess(word string, room *models.Room) error {
|
||||
}
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
}
|
||||
if err := saveRoom(room); err != nil {
|
||||
ctx, tx, err := repo.InitTx(context.Background())
|
||||
defer tx.Commit()
|
||||
if err != nil {
|
||||
b.log.Error("failed to init tx", "error", err)
|
||||
}
|
||||
if err := repo.ActionCreate(ctx, &action); err != nil {
|
||||
tx.Rollback()
|
||||
b.log.Error("failed to create action", "error", err, "action", action)
|
||||
return err
|
||||
}
|
||||
if err := repo.RoomUpdate(ctx, room); err != nil {
|
||||
tx.Rollback()
|
||||
b.log.Error("failed to save room", "room", room)
|
||||
err = fmt.Errorf("fn: checkGuess, failed to save room; err: %w", err)
|
||||
return err
|
||||
@ -231,16 +242,15 @@ func (b *Bot) BotMove() {
|
||||
b.log.Warn("turn limit is 0", "mimeResp", mimeResp)
|
||||
room.ThisTurnLimit = 9
|
||||
}
|
||||
if err := repo.ActionCreate(context.Background(), &action); err != nil {
|
||||
b.log.Error("failed to create action", "error", err)
|
||||
return
|
||||
}
|
||||
if err := saveRoom(room); err != nil {
|
||||
b.log.Error("failed to save room", "error", err)
|
||||
return
|
||||
}
|
||||
case models.UserRoleGuesser:
|
||||
// // deprecated
|
||||
// if err := b.checkGuesses(tempMap, room); err != nil {
|
||||
// b.log.Warn("failed to check guess", "mimeResp", tempMap, "bot_name", b.BotName)
|
||||
// continue
|
||||
// }
|
||||
guess, ok := tempMap["guess"].(string)
|
||||
if !ok || guess == "" {
|
||||
b.log.Warn("failed to parse guess", "mimeResp", tempMap, "bot_name", b.BotName)
|
||||
|
Reference in New Issue
Block a user